A shopping app's price-tracking chart shows, under each day, how many days you would have had to wait for a strictly higher price. prices[i] is the price on day i.
Write daysToWait(prices) that returns an array where position i is the number of days from day i to the next day with a higher price, or 0 if no later day is higher.
Input: prices = [60,64,63,58,57,61,68,64] Output: [1,5,4,2,1,1,0,0]
Day 1 (64) waits 5 days for 68; day 3 (58) waits 2 days for 61.
Input: prices = [30,40,50,60] Output: [1,1,1,0]
Every day is followed by a higher one.
1 <= prices.length <= 10^51 <= prices[i] <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #263 Days Until a Higher Price. 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.