Login

All Problems

Problem title

Difficulty

Avg time to solve

Find a Corresponding Node of a Binary Tree in a Clone of That Tree

Easy

20 mins

Cubic Square

Moderate

25 mins

Increase Number By 1

Easy

15 mins

Added Character

Easy

10 mins

Euler Totient Function Sum

Hard

60 mins

Maximise Dot Product

Hard

45 mins

Town Planning

Hard

35 mins

Count The Odd Numbers

Easy

15 mins

Largest Component

Moderate

45 mins

Binary Flip

Hard

15 mins

Problem

Submissions

0

Difficulty: EASY

Contributed By

Avg. time to solve

20 min

Problem Statement

```
1. ‘cloneTree’ is an exact copy of the ‘originalTree’.
2. All nodes in ‘originalTree’ are distinct.
3. The given node in the ‘originalTree’ will not be NULL.
4. You cannot change any of the two given trees.
```

```
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains elements of the tree in the level order form. The line consists of values of nodes separated by a single space. In case a node is null, we take -1 in its place.
The second line contains an integer ‘K’ which denotes the value of the reference node in ‘originalTree’.
For example, the level order input for the tree depicted in the below image.
```

```
50
13 72
3 25 66 -1
-1 -1 -1 -1 -1 -1
```

```
Level 1 :
The root node of the tree is 50
Level 2 :
Left child of 50 = 13
Right child of 50 = 72
Level 3 :
Left child of 13 = 3
Right child of 13 = 25
Left child of 72 = 66
Right child of 72 = ‘Null’
Level 4 :
All children are ‘Null’
The first not-null node(of the previous level) is treated as the parent of the first two nodes of the current level. The second not-null node (of the previous level) is treated as the parent node for the next two nodes of the current level and so on.
The input ends when all nodes at the last level are null(-1).
```

```
The above format was just to provide clarity on how the input is formed for a given tree.
The sequence will be put together in a single line separated by a single space. Hence, for the above-depicted tree, the input will be given as:
50 13 72 3 25 66 -1 -1 -1 -1 -1 -1 -1
```

```
For each test case, the output will be “1” if you have returned the correct node in ‘cloneTree’, else it will be “0”.
The output of each test case will be printed in a separate line.
```

```
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 5
1 <= N <= 3000
1 <= data <= 10 ^ 9
1 <= K <= 10 ^ 9
Where ‘data’ is the value of the nodes of the given binary tree, and ‘K’ represents the value of the given reference node in ‘originalTree’.
For a single test case, all given ‘data’ are distinct from each other and ‘K’ is equal to one given of ‘data’.
Time Limit: 1 Sec
```

```
2
1 -1 3 -1 4 -1 -1
4
50 -1 -1
50
```

```
1
1
```

```
For the first test case, the given tree is
Original tree
```

```
Clone Tree
```

```
The given tree in the second test case is.
Original tree.
```

```
Clone Tree
```

```
1
10 2 12 1 3 -1 13 -1 -1 -1 -1 -1 -1
2
```

```
1
```

```
For the first test case, the given tree is
Original tree
```

```
Clone Tree
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code