Given a circular integer array nums, return the next greater number for every element. In a circular array, the next greater number of the last element is the first element that is greater.
Use a monotonic stack with indices. Simulate the circular array by iterating twice (0 to 2n-1) using modulo. Only push indices during the first pass.
- Initialize result[] with -1.
- Iterate i from 0 to 2n-1, use idx = i%n.
- While stack non-empty and nums[stack.peek()] < nums[idx]: result[pop] = nums[idx].
- Only push index if i < n (first pass).
- Time Complexity: O(N)
- Space Complexity: O(N)