A walker's GPS logs the altitude at each step as the integer list nums (below sea level is negative). For every point she wants to know the altitude of the first point further along the walk that is strictly higher. Return a list res of the same length where res[i] is that altitude for point i, or -1 if nothing later is higher.
Examples
Input: nums = [3, 1, 2, 2, 5, 4]
Output: [5, 2, 5, 5, -1, -1]
Input: nums = [5, 4, 3]
Output: [-1, -1, -1]
Constraints
0 <= len(nums) <= 10**5-10**9 <= nums[i] <= 10**9- Target:
O(n)time (the nested-loop solution is too slow for the largest inputs)
Goals
- Keep a stack of indices still waiting for an answer
- Resolve waiting indices when a larger value arrives