Next Bigger Value on a Ring
Values sit on a ring: after the last element comes the first one again. For each position, find the first value strictly bigger than it when walking forward around the ring.
Return an array of those values, using -1 where no bigger value exists.
Example 1
Input: nums = [1, 2, 1] Output: [2, -1, 2] Explanation: The last 1 wraps around and finds the 2.
Example 2
Input: nums = [5, 4, 3, 2, 1] Output: [-1, 5, 5, 5, 5]
Constraints
- 0 <= nums.length <= 5 * 10^4
- -10^9 <= nums[i] <= 10^9
Hint 1
Keep a stack of indices still waiting for a bigger value.
Hint 2
Walk the array twice to simulate wrapping around the ring.
Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer, Game Developer
Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.