Nearest Greater to Left
Medium

Problem Statement

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

Examples

1Example 1
Input:
{ "arr": [ 1, 3, 2, 4 ] }
Output:
[ -1, -1, 3, -1 ]
2Example 2
Input:
{ "arr": [ 11, 13, 21, 3 ] }
Output:
[ -1, -1, -1, 21 ]
3Example 3
Input:
{ "arr": [ 4, 5, 2, 25 ] }
Output:
[ -1, -1, 5, -1 ]
Loading...

Sign in to Run Code and Submit