Identical Trees Problem Statement
Given two binary trees with 'N' and 'M' nodes respectively, determine if the two trees are identical. Return true
if they are identical, otherwise return false
.
Input:
The first line contains an integer T
denoting the number of test cases.
The first line of each test case contains elements in level order for the first binary tree, with node values separated by a space. Use -1 for null nodes.
The second line of each test case contains elements in level order for the second binary tree, formatted similarly.
Output:
For each test case, return True
if the trees are identical, or False
otherwise. Print each result on a new line.
Example:
Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
True
Constraints:
1 ≤ T ≤ 10
0 ≤ N ≤ 10^5
0 ≤ M ≤ 10^5
1 ≤ Node Data ≤ 10^9
- Time limit: 1 sec
Note:
You are not required to print anything; it has already been taken care of in the function implementation.
Be the first one to answer
Add answer anonymously...
Top Microsoft Corporation Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Microsoft Corporation Software Developer Intern
>
Microsoft Corporation Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app