As reported: Amazon SDE2 loop (Hyderabad, 2025), round 3 — DSA and problem solving, the first of two questions.
A rooted tree with n nodes (0 … n−1) is given as an array parent, where parent[i] is the parent of node i and the root has parent[root] = -1. Return the height of the tree — the number of nodes on the longest path from the root down to a leaf.
Example 1
parent = [4,3,0,6,6,3,-1,0]
Output: 4
The root is 6; one longest path is 6 → 4 → 0 → 2.
Example 2
parent = [-1,0,0,1,1,3,5]
Output: 5 (0 → 1 → 3 → 5 → 6)
Constraints: 1 ≤ n ≤ 10⁵; exactly one parent[i] is -1; the array describes a valid tree.
Code runner format: one line: parent as a JSON array. Implement treeHeight(parent); the harness prints the height.