For every value in nums, find the first value to its right that is strictly greater, and return a list of those values (-1 where there is none).
For [2, 1, 2, 4, 3] the answer is [4, 2, 4, -1, -1].
The starter code scans to the right from every position. It is correct but too slow for long lists.
Example 1
Input:
next_greater([2, 1, 2, 4, 3])
Output:
[4, 2, 4, -1, -1]
Example 2
Input:
next_greater([3, 2, 1])
Output:
[-1, -1, -1]
0 <= len(nums) <= 200000-10**9 <= nums[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.