BETA

Submissions : 173 Accuracy :

38.15

Next Right Node (Function Program)
         

Given a Binary tree and a key in the binary tree, find the node right to the given key. If there is no node on right side, then return -1.

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. The next line contains the edges of the tree. The last line of input contains the key.

Output:
Print the node right to the given key. If there is no node on right side, then return -1.

Constraints:
1<=T<=1000
1<=n<=1000
1<=data of node<=1000
1<=key<=1000

Example:
Input:

2
5
10 2 L 2 8 L 2 4 R 10 6 R 6 5 R
2
5
10 2 L 2 8 L 2 4 R 10 6 R 6 5 R
4

Output:
6
5

**For More Examples Use Expected Output**


Contributor: Ayush Govil


					   
Result:
It is recommended to test your code before clicking 'Submit' button!



                   



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