Objective: – Given a binary tree, Find the deepest left node in it.
- This approach is very similar to “Find the Deepest Node in a Binary Tree” with little modification.
- Take two global variables as “deepestlevel” and ” deepLeftNode”.
- starting with level=0, Do the inorder traversal and whenever you go down one level ( root.left OR root.right), increase the level by 1.
- Keep checking if the current node is the left child and deepestlevel < level, if yes then update the “deepestlevel ” and ” deepLeftNode “.
- At the end return ” deepLeftNode “, which will be the deepest node value.
- See the code for a better explanation.
Deapest Left child is: 4
Approach: – Without using global variables
We will keep track of the deepest left node and pass it along during recursion. Will take the Result object ( with data and level). See the code below for more understanding.
Deapest Left child is: 18