Loading...
Loading...
Loading...
A route moves along parent-child links between two nodes. Print the number of links on the longest possible route in the tree. A route may stay inside one side of the tree.
Example 1
Input
1 2 3 4 5
Output
3
The route 4, 2, 1, 3 has 3 links.
Example 2
Input
1 2 null 3 4 5 null null 6
Output
4
Try the problem first. Open one hint at a time.
At each node, the best route that bends there goes down both sides.
Keep the best while computing heights.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor