Tap here to switch tabs
Problem
Submissions

Problem: Next Greater Element II

Try to solve the Next Greater Element II problem.

Statement

Given a circular integer array nums, where the element after nums[nums.length - 1] is nums[0], return an array containing the next greater element for each element in nums.

The next greater element of nums[i] is the first element that is strictly greater than nums[i] when traversing forward from index i+1i + 1, with circular wraparound allowed.

If no greater element exists for nums[i], return −1-1 for that position.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Next Greater Element II

Try to solve the Next Greater Element II problem.

Statement

Given a circular integer array nums, where the element after nums[nums.length - 1] is nums[0], return an array containing the next greater element for each element in nums.

The next greater element of nums[i] is the first element that is strictly greater than nums[i] when traversing forward from index i+1i + 1, with circular wraparound allowed.

If no greater element exists for nums[i], return −1-1 for that position.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9