
Given a binary tree. (Don't assume it as BST).Write a method to print cousins of a given node.
Note :- Cosuins are node present at the same level but not having the same parent.
Example -
Cousin of 22 => 45,75 (7 is not cousin)
Cousin of 45 => 7, 22 (75 is not cousin)
Cosuin of 7 => 45, 75 (22 is not cousin)
function signature-
void printCousins(Node *root,Node *givenNode){
//Write implemenetation
}
}
30
/ \
/ \
15 60
/ \ / \
7 22 45 75
/ \
17 27