Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Maximum Depth of Binary Tree
Problem
Given the root of a binary tree, return its depth: the number of nodes on the longest path from the root down to any leaf. An empty tree has depth 0 and a single node has depth 1.
- The tree has at most 50,000 nodes and may be empty.
- Node values are integers; they play no role in the answer.
Examples
root = [8, 4, 12, 2, None, None, 15, 1]→4. The longest root-to-leaf path is8 → 4 → 2 → 1; the right side only reaches depth 3.root = [5, None, 9]→2. A right-skewed tree of two nodes.root = []→0. No nodes, no path.
Hints
- If you knew the depth of each subtree, how would you get the depth of the whole tree?
- What is the depth of an empty tree? Getting that base case right makes the recursion fall out.
- Post-order DFS returning
1 + max(depth(left), depth(right)); or BFS counting how many levels you dequeue.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.