 All Problems
Minimum Depth of Binary Tree
easy
tree
depth-first search
breadth-first search
binary tree
amazon
google

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Example 1:

Input:  3 9 20 null null 15 7
Output: 2

Example 2:

Input:  2 null 3 null 4 null 5 null 6
Output: 5

Constraints:

  • The number of nodes is in the range [0, 10⁵]
  • -1000 ≤ Node.val ≤ 1000

Input format: BFS level-order, space-separated, null for missing nodes.

Output format: Minimum depth.

Run to check your code against the sample cases, or submit to run every case