K-th Ancestor of a Node
Medium
Binary Lifting & LCA
A tree is given by a parent array (parent of the root is -1, nodes are 0-indexed). For each query (node, k) print the k-th ancestor of node, or -1 if it does not exist.
Constraints
1 <= n, q <= 5*10^4 1 <= k <= n
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.