Problem
You get the root root of a binary tree. In a binary tree, each node has at most two children: a left child and a right child.
Return the maximum depth of the tree. The maximum depth is the number of nodes on the longest path from the root to a leaf. A leaf is a node with no children. An empty tree has the depth 0.
The examples show each tree as a list in level order. This list gives the nodes row by row, from left to right. The value null marks a missing child.
Example 1
- Input:
- root = [4,2,9,null,null,6,11,null,7]
- Output:
- 4
- Explanation:
- The longest path is
4 -> 9 -> 6 -> 7. It has 4 nodes.
Example 2
- Input:
- root = [8,null,3]
- Output:
- 2
Example 3
- Input:
- root = []
- Output:
- 0
Constraints
- 0 <= number of nodes <= 10^4
- -100 <= Node.val <= 100
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- All Nodes Distance K in Binary Tree
Coding · Binary Tree · Breadth-First Search · Depth-First Search
- Amount of Time for Binary Tree to Be Infected
Coding · Binary Tree · Breadth-First Search · Depth-First Search
- Binary Tree Maximum Path Sum
Coding · Binary Tree · Depth-First Search · DP on Trees
- Balanced Binary Tree
Coding · Binary Tree · Depth-First Search · Tree
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Google
Leetcode 104. Maximum Depth of Binary Tree
Reported Oct 16, 2024 · 1 source report
JUNIOR
Source snapshot: Nov 12, 2026
View sourceLinkedIn
Leetcode 104. Maximum Depth of Binary Tree
Reported Jun 30, 2026 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
LinkedIn
Maximum Depth of Binary Tree
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 62.6. This is not an interview probability.
View sourceLinkedIn
Maximum Depth of Binary Tree