Medium
Quiz
#503 Next Greater Element II
APPROACH
Given a circular integer array nums where the successor of the last element wraps back to the first, return an array where each position holds the next greater number encountered when traversing the array circularly from that position. If no greater number exists in the full circular scan, use -1.
Example 1:
Input: nums = [1,2,1]
Output: [2,-1,2]
Explanation: The first 1's next greater number is 2;
The number 2 can't find next greater number.
The second 1's next greater number needs to search circularly, which is also 2.
Example 2:
Input: nums = [1,2,3,4,3]
Output: [2,3,4,-1,4]
1 of 4
1:00
What is the optimal approach for this problem?