Lowest common ancestor: Given a heap-indexed binary tree with unique non-null values and two values p and q, return their lowest common ancestor value, or null when either value is absent.
Input: A JSON object { "tree": (number|null)[], "p": number, "q": number }.
Output: A JSON number or null.
Constraints:
- 0 <= tree.length <= 100000
- Non-null tree values are unique
- A node may be its own ancestor
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: HARD. Variant: 9. Balance correctness, maintainability, and clear review-ready code.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked hard difficulty.
The signed-in workspace provides the tools required by the round, such as recording,