Given a binary tree, find the minimum depth of the tree. Minimum depth of a binary tree is the length of the shortest path of all paths from root to any leaf.
Please try solving this problem before jumping on the solution
Click to learn
Subscribe for more updates
Preparing for interviews? IDeserve team is here to help.
Create your profile
Create your profile, and here is what you will get:
1: Interview practice platform.
2: Once you are ready to take the interview, IDeserve team will help you get connected to the best job opportunities.
3: Personalized mentorship from IDeserve team once your interview process has started.
Creation of profile shouldn't take more than 2 minutes.
1: If root is null, return 0. 2: If root is a leaf, return 1. 3: If left node of root is not null, recursively call getMinDepth to get leftDepth, else set leftDepth to MAX_VALUE 4: If right node of root is not null, recursively call getMinDepth to get rightDepth, else set rightDepth to MAX_VALUE 5: Return 1 + min of leftDepth or rightDepth
Support us by whitelisting IDeserve in your ad-blocker.