Problem library

Rating Wait

Medium
monotonic stack

ratings lists a player's rating at the end of each day. For every day, find how many days the player has to wait until a day with a strictly higher rating. If no later day is higher, the answer for that day is 0.

Return the list of waits. The largest test has 40,000 days.

Examples

Input: ratings = [1200,1180,1250,1210,1300,1290]
Output: [2,1,2,1,0,0]
Input: ratings = [1500,1500,1400]
Output: [0,0,0]