A binary tree is given, the task is to check if all it's leaf nodes are at same level or not.
Solutions
Method 1: Recursion
We have two variables "leafLevel = -1" and "diff = 0", "leafLevel" will hold the level of very first leaf node.
We will traverse the tree in "level-order" passing current level in each recur, the idea is to check if other leaf nodes have same level as the first leaf (leafLevel); if not increase "diff".
In the end check if value of "diff" is changed, if yes that means leaf nodes are at different levels.
Complexity
The time complexity of this solution is O(n) and space complexity is O(n) due to call stack.