Close
Topic list
Minimum Depth Of Binary Tree
MEDIUM
20 mins
Stacks & Queues
Topics (Covered in this problem)
Problem solved
Skill meter
Stacks & Queues
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Minimum Depth Of Binary Tree

Contributed by
Anish De
Medium
0/80
Avg time to solve 20 mins
Success Rate 80 %
Share

## Problem Statement

#### You have been given a Binary Tree of integers, find the minimum depth of this Binary Tree. The minimum depth of a Binary Tree is the number of nodes along the shortest path from the root node down to the nearest leaf node.

##### Note:
``````A leaf is a node with no children.
``````
##### For example:
``````For the given binary tree
``````

``````Output: 2
The shortest path is from root node 1 to leaf node 2 which contains 2 nodes in the path. Hence, the minimum depth is 2.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````3
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
1 2 3 -1 -1 -1 -1
1 2 -1 3 -1 -1 -1
``````
##### Sample Output 1:
``````3
2
3
``````
##### Explanation For Sample Input 1:
``````For the first test case, the given tree is
``````

``````There are two shortest paths from the root to the leaf node i.e. {1 -> 3 -> 5} and {1 -> 3 -> 6}. Both paths contain 3 nodes, hence the minimum depth of this binary tree is 3.
``````
##### Sample Input 2:
``````1
1 2 -1 3 -1 -1 -1
``````
##### Sample Output 2:
``````3
``````
Auto
Console