Tree LCA Sets
Given a tree with $N$ nodes numbered $1$ to $N$, with a special property : the tree is rooted at node $1$, and $\text{par}_i < i$ for all nodes (the parent of each node has a strictly smaller index). For a subset of nodes $S$, we define an array $A$ of size $N$ in the following way: $$A_i = \min\limits_{x \in S}(\text{lca}(x, i))$$ Here, $\text{lca}(x, y)$ denotes the lowest common ancestor o
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start