Difficulty Level : Easy
Submissions : 64
Asked In :
Marks :10
: 2 | : 4
Given two binary trees, overlap $$$Tree-2$$$ over $$$Tree-1$$$.
Note: The merging process must start from the root nodes of both trees.
The first line of input contains two integers $$$n$$$ and $$$m$$$ — the length of two arrays representing $$$Tree-1$$$ and $$$Tree-2$$$. $$$(1 \le n,m \le 10^5)$$$
The second input line contains $$$n$$$ single space-separated integer values representing $$$Tree-1$$$. $$$(0 \le values \le 10^6)$$$
The second input line contains $$$m$$$ single space-separated integer values representing $$$Tree-2$$$. $$$(0 \le values \le 10^6)$$$
$$$0$$$ node value represents a null node.
It is guaranteed that the tree input given will be valid.
An array represents the tree formed after overlapping. The output array should be in the same format as the input, performing a level-order tree traversal.
3 4 1 2 3 4 5 6 7
4 5 6 7 0
5 6 1 0 2 0 3 1 2 0 3 0 4
1 2 2 3 0 0 3 4 0
5 6 1 2 3 0 4 5 6 0 0 9 10
5 6 3 0 9
7 7 1 0 2 0 3 0 4 5 6 0 7 0 8 0
5 6 2 7 0 0 3 8 0 0 4
A tree represented by array $$$[5,6,0,0,9]$$$ is 5 as root with the left child as 6 and 6 has right child as 9.
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.