Next Greater Element II

Given a circular integer array nums, return an array where answer[i] is the first strictly greater value encountered while moving right from index i. After…

Given a circular integer array `nums`, return an array where `answer[i]` is the first strictly greater value encountered while moving right from index `i`. After the last position, the scan continues from index `0`. Return `-1` when no strictly greater value exists.

- `1 <= nums.length <= 100000` - `-1000000000 <= nums[i] <= 1000000000` - Each answer must come from at most one complete circular scan after its position.

Example 1: input nums = [1,2,1]; output [2,-1,2]. The last 1 wraps to the first position and then finds 2.

Example 2: input nums = [5,4,3,2,1]; output [-1,5,5,5,5]. Every value except 5 reaches 5 after wrapping; no value is greater than 5.

Category: Stack. Topic: stack. Difficulty: Medium. Patterns: monotonic-stack.