Given a binary tree, find depth of deepest odd level leaf node. For example, in the following binary tree
1 / \ 2 3 / \ 4 5 / \ 6 7 \ / 8 9 / 10
deepest odd level leaf node is 8 and depth is 5.
Video coming soon!
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.
Traverse the tree and keep track of current level of the node. Current level of a node can be easily tracked by maintaining a variable 'currLevel'. Level of Root node is 1. Increment 'currLevel' while traversing for left and right subtrees. While traversing: 1: If root is null, return 0. 2: Else if we find a leaf node and the current level is odd, return the current level. 3: Else return maximum of (maximum depth of odd level leaf node found in left subtree, maximum depth of odd level leaf node found in right subtree).
Support us by whitelisting IDeserve in your ad-blocker.