Nearest Greater to Right
Medium

Problem Statement

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

Examples

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

Sign in to Run Code and Submit