Dashboard
LC #111

Minimum Depth of Binary Tree

Pattern · ?AmazonGoogleMicrosoft

Problem

Find the minimum depth — the shortest path from root to the nearest leaf node.

Constraints

  • 0 ≤ n ≤ 10⁵
  • -1000 ≤ Node.val ≤ 1000
  • A leaf is a node with no children

Example

Input
root = [3, 9, 20, null, null, 15, 7]
Output
2
Why
Shortest path root→leaf is 3→9 (depth 2). Not 3→20→15 (depth 3)

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗