Standard Bar Stack and Queues · Monotonic Stack and Queue O(n) · O(n)
A circular conveyor carries sensor modules around a loop, so every module can look past the end of the belt and keep scanning from the start. For each module, report the first module encountered on the forward trip whose reading is strictly higher — wrapping around the loop if needed.
Input: An integer array nums representing the circular arrangement.
Output: Return an array where entry i is the next strictly greater value reachable moving forward (circularly) from nums[i], or -1.
1 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^9Input: {"nums":[1,2,1]}
Output: [2,-1,2]
The second 1 wraps around to find 2; the maximum 2 finds nothing greater even going full circle.
Input: {"nums":[5,4,3,2,1]}
Output: [-1,5,5,5,5]
Strictly decreasing layout: only the first element (wrapping) sees a greater value.