Nearest Smaller to Right
Medium

Problem Statement

Given an array of integers, find the nearest smaller element to the right for each element. If no such element exists, consider it -1.

Examples

1Example 1
Input:
{ "arr": [ 4, 5, 2, 10, 8 ] }
Output:
[ 2, 2, -1, 8, -1 ]
2Example 2
Input:
{ "arr": [ 1, 2, 3, 4, 5 ] }
Output:
[ -1, -1, -1, -1, -1 ]
3Example 3
Input:
{ "arr": [ 5, 4, 3, 2, 1 ] }
Output:
[ 4, 3, 2, 1, -1 ]
Loading...

Sign in to Run Code and Submit