Kth Ancestor of a Tree Node
HardLeetCodeAdvanced Trees (BST, LCA, Tree DP)
Approach hintTry it first, then revealHide
Precompute binary lifting tables where up[j][v] is the 2^j-th ancestor of v, then answer a query by jumping along the set bits of k. O(n log n) build and O(log n) per query.