Desktop only
Coding Challenges are optimized for Desktop
Come back on a wider screen - the live editor needs room to breathe. You can still read the problem brief above.
Come back on a wider screen - the live editor needs room to breathe. You can still read the problem brief above.
def lca(self, a: int, b: int) -> int:
"""Return the lowest common ancestor of a and b."""def __init__(self, parent: dict[int, int | None]) -> None:
"""Preprocess the parent map so later queries only pay O(depth)."""def lca_many(self, ids: list[int]) -> int:
"""Return the lowest common ancestor of every id in the list."""def answer_queries(self, queries: list[tuple[int, int]]) -> list[int]:
"""Answer every (a, b) query, reusing preprocessed data."""