Reported interview periodDec 2025–Aug 2026
Ancestor lookup with upward-only links
Every node in a tree stores only the id of its parent. Given two node ids, find their deepest shared ancestor using those upward links alone.
Practice focusRequirements - Line one is the node count n . Line two gives n parent ids in node order: the value at position i is the parent of node i , and a root is marked -1 . - Line three holds the two query ids separated by whitespace. - Node identity is the array position, so ids run from 0 to n - 1 . - A node counts as an ancestor of itself, so querying a node against one of its descendants returns that node. - Return the id of the deepest common ancestor as a decimal string, or -1 when the two nodes belong to different trees.…