Second Larger Item to the Right
For every item of nums, look at the items to its right that are strictly larger than it, in the order they appear. Return a list with the second of them for every item, or -1 where there are fewer than two.
Example 1
nums [3,5,1,4,6]
returns [4,-1,6,-1,-1]
To the right of the 3 the larger items are 5, then 4, then 6: the second is 4. After the 5 only the 6 is larger. After the 1 come 4 and then 6.
Example 2
nums [7,7,7]
returns [-1,-1,-1]
Equal items are not larger, so nothing ever counts.
Constraints
1 <= len(nums) <= 3000 <= nums[i] <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Smallest Pick With a Letter QuotaHard
- Tiny Language With LetHard
- Value of a Logic FormulaHard
- Close Every BracketBeginner
- Crate PileBeginner
- Dead-End DrivewayBeginner
- Elevator TripsBeginner
- Flip the PancakesBeginner