Login

All Problems

Problem title

Difficulty

Avg time to solve

Capacity To Ship Packages Within D Days

Moderate

15 mins

Fruits and Baskets

Hard

50 mins

Smallest Number With At least N Trailing Zeros In Factorial

Easy

10 mins

Ninja And Geometry

Easy

15 mins

Count with K different characters

Easy

15 mins

Calculate XOR

Easy

23 mins

Serialize And Deserialize BST

Easy

15 mins

Append Nodes

Moderate

38 mins

2’s Complement

Easy

20 mins

Minimum number of swaps

Moderate

--

Problem

Submissions

5

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
Serialization is the process of converting an object into a stream of bytes.
Deserialization is the opposite process of creating an object from a stream of bytes.
You can apply your own serialization and deserialization algorithms.
```

```
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains elements 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.
For example, the input for the tree depicted in the below image will be:
```

```
1
2 3
4 -1 5 6
-1 7 -1 -1 -1 -1
-1 -1
```

```
Level 1 :
The root node of the tree is 1
Level 2 :
Left child of 1 = 2
Right child of 1 = 3
Level 3 :
Left child of 2 = 4
Right child of 2 = null (-1)
Left child of 3 = 5
Right child of 3 = 6
Level 4 :
Left child of 4 = null (-1)
Right child of 4 = 7
Left child of 5 = null (-1)
Right child of 5 = null (-1)
Left child of 6 = null (-1)
Right child of 6 = null (-1)
Level 5 :
Left child of 7 = null (-1)
Right child of 7 = null (-1)
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:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
```

```
Print the level order traversal of the Binary Search Tree after Deserialization separated by spaces. It should match with the level order traversal of the initially given tree.
Print the answer of each test case in a new line.
```

```
None of the pointers in the new tree should point to nodes in the original tree, otherwise, the expected output can be different.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 50
1 <= N < 10^4
0 <= data < 10^4 and data!=-1
Time Limit: 1 sec
```

```
2
24 15 33 12 21 30 36 9 -1 18 -1 27 -1 -1 -1 -1 -1 -1 -1 -1 -1
15 9 21 7 13 19 23 5 -1 11 -1 17 -1 -1 -1 -1 -1 -1 -1 -1 -1
```

```
24 15 33 12 21 30 36 9 18 27
15 9 21 7 13 19 23 5 11 17
```

```
In the first test case, The values of the nodes are 24, 15, 33, 12, 21, 30, 36, 9, 18, and 27. After performing Serialization and Deserialization, the tree should remain the same. So, the level order traversal of the tree is 24, 15, 33, 12, 21, 30, 36, 9, 18, and 27.
In the second test case, The values of the nodes are 15, 9, 21, 7, 13, 19, 23, 5, 11, and 17. After performing Serialization and Deserialization, the tree should remain the same. So, the level order traversal of the tree is 15, 9, 21, 7, 13, 19, 23, 5, 11, and 17.
```

```
2
1 2 3 -1 -1 -1 -1
25 16 34 13 22 31 37 -1 -1 -1 -1 -1 -1 -1 -1
```

```
1 2 3
25 16 34 13 22 31 37
```

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