Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Minimum Depth of Binary Tree

Medium Acceptance 60.25% Points 30

You are given the root of a binary tree. Your task is to find its minimum depth — the number of nodes along the shortest path from the root node down to the nearest leaf node.

A leaf node is a node with no left or right child.

Return the minimum number of nodes present on any root-to-leaf path.

Examples
Example 1

image Input: root = [3,9,20,null,null,15,7]
Output: 2
Explanation: The shortest root-to-leaf path is 3 → 9, which contains 2 nodes.

Example 2

image Input: root = [2,null,3,null,4,null,5,null,6]
Output: 5
Explanation: The tree is skewed, so the only root-to-leaf path has 5 nodes.

Example 3

image Input: root = []
Output: 0
Explanation: An empty tree has a minimum depth of 0.

Constraints
    • 0 = Number of nodes = 105
    • -10? = Node.data = 10?
Topics
Tree Traversal Binary Tree
Companies
Microsoft Wayfair Nutanix
Added 08 Aug 2026 60.25% acceptance
Ln 1, Col 1Sign in to save your code
1 2 3 4 5 6 7
3