Nearest Smaller to Left
Medium

Problem Statement

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

Examples

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

Sign in to Run Code and Submit