BETA

Difficulty Level: Easy

Submissions: 2998 Accuracy:

23.28%

Print Common Nodes in BST (Function Problem)
       

Given two Binary Search Trees, task is to complete the function printCommon, which print's the common nodes in them. In other words, find intersection of two BSTs.

Example

root1

                 5
              /    \
            1       10
          /   \    /
         0     4   7
                    \
                     9

root2:

               10
             /    \
            7     20
          /   \
         4     9

Output: 4 7 9 10


Input:
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow. For each test case two root nodes "root1" and "root2" pointing to the two tree's, are send to the function printCommon.

Output:
For each test case output a new line, containing space separated integers denoting the intersection of two BST's in sorted order.

Constraints:
1<=T<=50
1<=N<=50

Example:
Input:

1
7
5 1 10 0 4 7 9
5
10 7 20 4 9 

Output:
4 7 9 10

 

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

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

Contributor: Harshit Sidhwa


					   
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.