Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5604 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 799 |

@sriramgoparaju99 | 737 |

@Manikanta punnam | 629 |

@rdakka | 606 |

@prankursharma31 | 597 |

@praveenbgp6 | 546 |

@sanskar94511 | 531 |

@purohitmn02 | 529 |

@yashkaril4 | 517 |

@abhikarshgupta | 474 |

@rohitgarg2825 | 464 |

Complete Leaderboard |

Given a binary tree, find its minimum depth.

**Example 1:**

Input:1 / \ 3 2 / 4Output:2Explanation:Minimum depth is between nodes 1 and 2 since minimum depth is defined as the number of nodes along the shortest path from the root node down to the nearest leaf node.

**Example 2:**

Input:10 / \ 20 30 \ \ 40 60 / 2Output:3Explanation:Minimum depth is between nodes 10,20 and 40.

**Your Task: **

You don't need to read input or print anything. Complete the function **minDepth()** which takes the root node as an input parameter and returns the minimum depth.

**Expected Time Complexity: **O(N)

**Expected Auxiliary Space: **O(height of the tree)

**Constraints:**

1 ≤ N ≤ 10^5

Login to report an issue on this page.

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

Yes
Minimum Depth of a Binary Tree

...