Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Minimum Depth of a Binary Tree
Easy Accuracy: 52.43% Submissions: 20719 Points: 2

Given a binary tree, find its minimum depth.

Example 1:

Input:
            1
          /   \
         3     2
        /
       4           

Output: 2

Explanation:
Minimum depth is between nodes 1 and 3.

Example 2:

Input:
             10
          /     \
        20       30
          \        \   
          40        60 
                   /
                  2 

Output: 3

Explanation:
Minimum depth is between nodes 10,20 and 40.


Your Task:  
You dont need to read input or print anything. Complete the function minDepth() which takes root node as input parameter and returns the minimum depth.

 

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(height of tree)

 

Constraints:
1 ≤ N ≤ 10^5

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Minimum Depth of a Binary Tree

Output Window