Back to course home
0% completed
Vote For New Content
Problem 4: Next Greater Element (easy)
Problem Statement
Given an array, print the Next Greater Element (NGE) for every element.
The Next Greater Element for an element x is the first greater element on the right side of x in the array.
Elements for which no greater element exist, consider the next greater element as -1.
Examples
Example 1:
Input: [4, 5, 2, 25]
Output: [5, 25, 25, -1]
Example 1:
Input: [13, 7, 6, 12]
Output: [-1, 12, 12, -1]
Example 1:
Input: [1, 2, 3, 4, 5]
Output: [2, 3, 4, 5, -1]
Constraints:
- 1 <= arr.length <= 10<sup>4</sup>
- -10<sup>9</sup> <= arr[i] <= 10<sup>9</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself