Error
|
|
---|---|
@Ibrahim Nash | 6379 |
@blackshadows | 6329 |
@mb1973 | 5358 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3357 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@ritiksethi21 | 1050 |
@aroranayan999 | 807 |
@RizulBansal | 685 |
@ashishtrehan002 | 538 |
@hemantgarg923 | 528 |
@simrangoyal | 526 |
@ronaldo77 | 520 |
@anishrajan | 505 |
@thanosagain | 505 |
@ssparteek470 | 495 |
@rahul2312 | 491 |
Complete Leaderboard |
Given a binary tree of size N, your task is to complete the function printAllDups(), that finds and prints all duplicate subtrees from the given binary tree.
For each duplicate subtrees, you only need to print the root node value of any one of them.
Two trees are duplicate if they have the same structure with same node values.
Example:
Input :
Output :
and
Explanation: Above Trees are two duplicate subtrees.
Therefore, you need to return above trees root in the
form of a list.
Input:
The function takes a single argument as input, the reference pointer to the root node of the binary tree.
There will be T, test cases and for each test case the function will be called separately.
Output:
The function should print space separated root node value of all the duplicate subtrees. If no duplicate subtree is present in the binary tree print "-1 ".
Note: Need not print new line at the end.
Note: Print the nodes values in sorted order(ascending).
Constraints:
1<=T<=100
1<=N<=100
Example:
Input:
3
5
10 20 L 20 25 L 10 30 R 30 20 L 20 25 L
6
1 2 L 1 3 R 2 4 L 3 2 L 2 4 L 3 4 R
6
10 8 L 8 3 L 10 2 R 2 9 L 9 4 R 2 6 R
Output:
20 25
2 4
-1
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.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes