ORIGINAL CODING QUESTION
Rooted mentoring tree height
Return the maximum number of edges from root 0 to any node. A single-node tree has height 0.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, followed by n parent IDs. Node 0 is root with parent -1; every other parent is in [0, node ID).
Constraints
1 ≤ n ≤ 200; the parent list describes one connected rooted tree.
Example 1
Input
4 -1 0 1 1
Output
2
The deepest nodes have depth 2.
Example 2
Input
1 -1
Output
0
The root depth is 0.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
A child has parent depth plus one.
Hint 2
Parents appear earlier in the input.
Hint 3
Keep the greatest computed depth.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →