Login

All Problems

Problem title

Difficulty

Avg time to solve

Longest Subarray With No Repetitions

Moderate

25 mins

Boat Journey

Hard

60 mins

Linear Equation

Moderate

40 mins

Battalions and tanks

Moderate

10 mins

Add in matrix

Easy

15 mins

Word Pattern

Easy

15 mins

Buildings Projection

Moderate

15 mins

URL Shortener

Easy

10 mins

BST from Preorder

Moderate

--

Ninja and the Nested Ranges II

Hard

45 mins

Problem

Submissions

1

Problem Statement

```
You are given preOrder = [10, 5, 1, 7, 40, 50], the binary search tree from the given preorder traversal is
```

```
The first line of input contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing the size of the preorder array.
The second line of each test case contains ‘N’ space-separated integers representing the preorder traversal of the tree.
```

```
For each test, ‘N’ space-separated integers will be printed representing the inorder traversal of the tree.
Print a separate line for each test case.
```

```
1 <= T <= 10
1 <= N <= 10^6
1 <= preOrder[i] <= 10^9
It is guaranteed that the sum of ‘N’ over all test cases does not exceed 10^6.
Time Limit: 1 sec.
```

```
You do not need to print anything. It has already been taken care of. Just implement the function.
```

```
2
6
10 5 1 7 40 50
6
8 5 1 7 10 12
```

```
1 5 7 10 40 50
1 5 7 8 10 12
```

```
For the first test case, preOrder = [10, 5, 1, 7, 40, 50], the binary search tree from the given preorder traversal is
```

```
Hence the answer is [1, 5, 7, 10, 40, 50].
For the second test case, preOrder = [8, 5, 1, 7, 10, 12], the binary search tree from the given preorder traversal is
```

```
Hence the answer is [1, 5, 7, 10, 40, 50].
```

```
2
3
2 1 3
3
1 3 2
```

```
1 2 3
1 2 3
```

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