BETA

Difficulty Level:

Easy

Total Submissions: 401 Accuracy:

28.43%

Next Right Node (Function Problem)
         

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 Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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