Loading...
Loading...
Loading...
In a chart, a chain runs from the top node down to a node with no children. Print the number of nodes on the longest chain. An empty chart has length 0.
Example 1
Input
1 2 3 4 null null 5
Output
3
The chain 1, 2, 4 has 3 nodes.
Example 2
Input
7
Output
1
Try the problem first. Open one hint at a time.
Ask both children for their height.
The height is 1 plus the larger answer.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor