Ctrl K
Problem

Waiting for a Higher Price

Medium · Waiting for a Higher Price

A shop records an item's price at the end of each day: `prices[i]` is the price on day `i`. For every day, find out how many days you would have to wait until the price is strictly higher than on that day. Return a list of the same length where element `i` is the number of days from day `i` to the nearest later day with a higher price. If there is no such day, put `0`. Comparing each day with all the following ones is O(n²). Try to do it in O(n).…

Solve the problem →