Simple example
Input
nums = [4, 5, 2, 25]
Output
[5, 25, 25, -1]
4 -> 5, 5 -> 25, 2 -> 25, 25 -> -1 since no greater element to its right.
Full lesson preview
For each element in an array, find the next element to its right that is greater; return -1 if none exists.
Problem statement
Task
Examples
Input
nums = [4, 5, 2, 25]
Output
[5, 25, 25, -1]
4 -> 5, 5 -> 25, 2 -> 25, 25 -> -1 since no greater element to its right.
Input format
Output format
Constraints
Samples
Input
nums = [2, 2, 2]
Output
[-1, -1, -1]
No element has a strictly greater element to its right.