Standard Bar Binary Trees · Medium Problems O(n) · O(h)
A broadcast network diagrams its relay masts as a binary tree, with the studio at the root and each mast feeding at most two downstream masts. Signal-latency budgeting depends on one number: how many masts a packet traverses on the longest root-to-leaf chain. The network planner needs that count for every redesigned topology before signing off on hardware.
Input: The root of a binary tree given as a level-order array where null marks a missing child.
Output: Return an integer: the number of nodes on the longest root-to-leaf path.
0 <= number of nodes <= 10^5-100 <= node value <= 100Input: {"tree":[3,9,20,null,null,15,7]}
Output: 3
The deepest chain is 3 -> 20 -> 15 (or -> 7): three nodes.
Input: {"tree":[1,2]}
Output: 2
Root plus its single left child spans two nodes.