Mirror of a given node
Submissions: 1142   Accuracy:

37.83%

  Difficulty: Medium   Marks: 4

Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the number of edges. Then next line contains the edges of the tree. The last line contains the target node of which mirror is to be found out.

Output:
Print the mirror node of the target node and if doesn't exist print -1.

Constraints:
1<=T<=100
1<=n<=100
1<=data of node<=100
1<=target<=100

Example:
Input:

2
8
1 2 L 2 4 L 4 7 R 1 3 R 3 5 L 3 6 R 5 8 L 5 9 R
4
8
1 2 L 2 4 L 4 7 R 1 3 R 3 5 L 3 6 R 5 8 L 5 9 R
7

Output:
6
-1

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

Contributor: Ayush Govil
Author: Ayush Govil 1


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.