LeetCode 104 ·
Easy
Maximum Depth of Binary Tree
Return the maximum depth (number of nodes on the longest root-to-leaf path).
Try it
Step through the core mechanic. The simulator below runs the recursion shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Recursion — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Depth of a node is 1 + max(depth(left), depth(right)); null is 0. The recursion returns each subtree's height up to its parent.
| Aspect | Value |
|---|---|
| Pattern | Recursion |
| Recognise it by | Height of a tree. |
| Time complexity | O(n) |
| Space complexity | O(h) |
| Difficulty | Easy |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.