Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

89. Next Greater Element II

MediumDay 26 of 60Stack & Queue

Given a circular integer array nums (the element after the last one is the first one), return the next greater number for every element. The next greater number of x is the first strictly larger value you meet when walking forward from x, wrapping around the end if needed. If no such value exists, use -1.

Example 1
Input: nums = [1,2,1]
Output: [2,-1,2]
The last 1 wraps around and finds 2.
Example 2
Input: nums = [1,2,3,4,3]
Output: [2,3,4,-1,4]
Constraints
  • 1 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
Hints
Frequently asked at: Amazon, Google, Flipkart
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min