Loading...
You are given a circular integer array nums, so the element after nums[nums.length - 1] is nums[0].
For every element, find its next greater value: the first element strictly greater than it when scanning forward from its position, wrapping around to the start if needed. An element never compares against itself more than once, so if a full circular scan finds no strictly greater element, its answer is -1.
Return the array of answers, one per position.
Input: nums = [1,2,1]
Output: [2,-1,2]
Explanation: The first 1's next greater value is 2. The 2 has no greater element anywhere. The last 1 wraps around and finds the 2 at index 1.
Input: nums = [1,2,3,4,3]
Output: [2,3,4,-1,4]
Explanation: Each element takes the first strictly greater value ahead of it; the 4 has none, and the trailing 3 wraps around to the 4 at index 3.
nums.length ≤104nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.