This post is completed by 2 users
|
Add to List |
61. Determine If Two Nodes are Cousins
Objective: Given a binary tree and two nodes, Check if they are cousins
Cousin Nodes: Cousin nodes are the nodes at the same level in the tree and whose parents are siblings.
Example:

Approach:
- Check the height of both the nodes, if heights are different then return false.
- Check if both the nodes have the same parent, if yes then return false.
- else return true.
Node 2 and Node 3 are cousins??? false Node 7 and Node 9 are cousins??? true