Deepest Branch
easyA company's reporting structure is a binary tree: each manager has at most two direct reports. HR wants to know how many layers of management exist — the number of nodes on the longest chain from the CEO down to someone with no reports.
Given the root of a binary tree, return its maximum depth: the count of nodes along the longest root-to-leaf path. An empty tree has depth 0.
Tests pass a level-order array; implement the core in _depth on real nodes.
Example 1
in values = [3, 9, 20, null, null, 15, 7]
out 3
Longest chain: 3 → 20 → 15 (or 3 → 20 → 7).
Example 2
in values = [1, null, 2]
out 2
Example 3
in values = []
out 0
Constraints
- · 0 <= number of nodes <= 10^4
- · -100 <= node value <= 100
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.