Find if two nodes are cousins in Binary Tree
We say two nodes in a binary tree are cousins if they are on same level but have different parents
- Find the parent nodes and levels of the given nodes
- Store these in a pair to compare
- If they happen to have different parents and same level, then they are cousins, else they are not!
The code should be self explanatory.
Thanks for Reading!!1