A looping product carousel shows cards in a circle: after the last card comes the first again. ratings[i] is card i's rating.
Write nextLargerAround(ratings) that returns, for each card, the first strictly larger rating you meet when moving forward around the circle from it, or -1 if no card is larger.
Input: ratings = [1,2,1] Output: [2,-1,2]
The last 1 wraps around to the first card and keeps going until it meets 2.
Input: ratings = [1,2,3,4,3] Output: [2,3,4,-1,4]
The last 3 wraps around and finds 4.
1 <= ratings.length <= 10^5-10^9 <= ratings[i] <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #265 Next Larger in a Looping Carousel. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.