Maximum Depth of Binary Tree
Learn how to solve the 'Maximum Depth of Binary Tree' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
The tree is represented as a level-order list where None represents a missing node. Implement a function maxDepth(root: list) -> int.
- •The number of nodes in the tree is in the range [0, 10000]
- •-100 <= Node.val <= 100
Examples
[3,9,20,None,None,15,7]
3
The tree has 3 levels: root [3], second level [9,20], third level [15,7]. The longest path is 3->20->15 or 3->20->7, both of depth 3.
[1,None,2]
2
The tree has root 1 with only a right child 2. Depth is 2.
[]
0
An empty tree has depth 0.
Need a Hint?
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.