Check leaf at same level of binary tree

All leaf at same level

Given a Binary Tree, check if all leaves are at same level or not.

Solution:

  • Find the height of binary tree then,
  • For each leaf check with same height.

Latest Source Code:
Github: BinaryTreeLeafAtSameLevelChecker.java


Output:

   12       
  / \   
 /   \  
 5   7   
/     \ 
3     1 
                
Leaf at same level ? true
   12       
  / \   
 /   \  
 5   7   
/       
3       
                

Leaf at same level ? false
       12               
      /         
     /          
    /           
   /            
   5               
  / \           
 /   \          
 3   9           
/   /           
1   2           
                                

Leaf at same level ? true
Author: Hrishikesh Mishra