New update is available. Click here to update.

Last Updated: 27 Jan, 2021

Difficulty: Moderate

```
If the given array is [ 2, 3, 1], we need to return [1, 1, -1]. Because for 2, 1 is the Next Smaller element. For 3, 1 is the Next Smaller element and for 1, there is no next smaller element hence the answer for this element is -1.
```

```
The first line of input contains an integer ‘T’ which contains the number of test cases.
The first line of each test case contains an integer 'N' denoting the number of elements in the array 'ARR'.
The second line of each test case contains 'N' space-separated integers denoting the array 'ARR'.
```

```
For each test case, print a single line containing 'N' space-separated integers denoting the value of Next Smaller Element for each of the 'N' array elements.
The output for each test case will be printed in a separate line.
```

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

```
1 <= T <= 10
1 <= N <= 10 ^ 5
0 <= ARR [i] <= 10 ^ 9
Time Limit: 1sec.
```

SIMILAR PROBLEMS

Missing Number

Posted: 30 Oct, 2022

Difficulty: Easy

Longest Subarray With Zero Sum

Posted: 3 Nov, 2022

Difficulty: Moderate

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Popular Interview Problems: