BETA

Difficulty Level: Hard

Submissions: 2592 Accuracy:

36.81%

Fixing Two nodes of a BST (Function Problem)
     

Two of the nodes of a Binary Search Tree (BST) are swapped. Fix (or correct) the BST.

Input:

First line consists of T test cases. First line of every test case consists of N, denoting number of elements in BST. Second line of every test case consists 3*N elements 2 integers and a character.

Note: It is guaranteed than the given input will form BST ,except for 2 nodes that will be wrong.

Output:
Return the fixed BST.

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

Example:
Input:

1
4
10 5 L 10 8 R  5 2 L 5 20 R 
Output:
1

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

Contributor: Saksham Raj Seth


					   
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.