easy

Next Greater Element

For every element of an integer array, find the first element to its right that is strictly larger; report -1 when none exists. Values in the array are distinct.

Constraints
  • 1 ≤ n ≤ 10^4
  • 0 ≤ nums[i] ≤ 10^4
  • All values distinct
Examples
in: nums = [4,1,2,10,3]
out: [10,2,10,-1,-1]

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.