Check if two Nodes are Cousins
Submissions: 8514   Accuracy:

32.4%

  Difficulty: Easy   Marks: 2

Given the binary Tree and the two nodes say ‘a’ and ‘b’, determine whether the two node values are cousins of each other or not.

Two nodes value are cousins of each other if they are at same level and have different parents.

Input:
First line consists of T test cases. First line consists of a integer N denoting number of nodes. Second line consists of N triplets consisting of 2 integers and a character. Third line consists of 2 integers to check whether they are cousins or not.

Output:
Single line output, print "1" if they are cousins else "0". You don't have to print just return true or false.

Constraints:
1<=T<=100
1<=N<=100

Example:
Input:

2
2
1 2 L 1 3 R
2 3
4
1 2 L 1 3 R 3 4 R 2 5 L
4 5
Output:
0
1

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.