Organization Hierarchy Depth
Problem
A quantitative trading firm organizes its team as a binary hierarchy. The CEO is at the top, and each manager has at most two direct reports. Given this hierarchy represented as a binary tree, determine the depth of the longest chain of command — that is, the number of levels from the CEO down to the most junior analyst.
An empty firm (no employees) has depth 0.
Input Format
A single line containing space-separated values representing the hierarchy in level-order. Use null for positions where no employee exists. An empty line represents an empty hierarchy.
Output Format
A single integer representing the maximum depth of the hierarchy.
Examples
10 5 15 3 7 null 20
3
The hierarchy has CEO (10), two VPs (5, 15), and analysts (3, 7, 20). The longest chain is 10 -> 15 -> 20 with depth 3.
42
1
A single executive with no reports has depth 1.
Constraints
- •0 ≤ number of nodes ≤ 10^4
- •-10^4 ≤ node value ≤ 10^4
- •Input is given in level-order with 'null' for missing nodes