algorythms
Tree BFS
LC #111Easy

Minimum Depth of Binary Tree

Tree BFS
AmazonGoogleMicrosoft

Problem

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

treebfsdfs

Constraints

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

Example

Inputroot = [3, 9, 20, null, null, 15, 7]
Output2
Why

Shortest path root→leaf is 3→9 (depth 2). Not 3→20→15 (depth 3)

Hints — reveal one at a time