Show the best price still to come
Your task
A pricing dashboard shows, next to each day in a price history, the best price still to come.
Write best_price_ahead(prices) that returns, for each day, the highest price on any later day.
Input and output:
prices: a list of 0 to 100,000 daily prices, each an integer from 0 to 1,000,000.- Returns a list of integers of the same length, one per day, in the same order.
Rules:
- The value for day
iis the largest price among the days after dayi. Dayiitself does not count. - The last day has no later days, so its value is -1.
- An empty list returns an empty list.
Examples
best_price_ahead(prices: list[int]) -> list[int]Example 1
Input
best_price_ahead([3, 7, 1, 4])Output
[7, 4, 4, -1]Example 2
Input
best_price_ahead([5, 5, 2, 8, 0])Output
[8, 8, 8, 0, -1]