Problems / Next Greater Element (Circular)
Medium

Next Greater Element (Circular)

Medium 96 submissions 25 coins +100 XP
Monotonic Stack Stack
Problem Description
`nums` is circular (the element after the last is the first). For each element, return the first strictly greater value found by walking forward, wrapping around if needed, or `-1` if none exists. **Example 1:** ``` Input: nums = [1, 2, 1] Output: [2, -1, 2] ``` **Example 2:** ``` Input: nums = [1, 2, 3, 4, 3] Output: [2, 3, 4, -1, 4] ``` **Example 3:** ``` Input: nums = [5, 5] Output: [-1, -1] ```
Constraints
- `1 <= nums.length <= 10^4` - `-10^9 <= nums[i] <= 10^9`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share