Quant Memo
Coding/●●●●●

Days until a higher price

Asked at Optiver, IMC

Given a series of daily prices, for each day report how many days you must wait until a strictly higher price appears. If no higher price ever comes, report 0.

prices = [73, 74, 75, 71, 69, 72, 76, 73]
-> [1, 1, 4, 2, 1, 1, 0, 0]

Return the wait array in O(n)O(n).

Show a hint

Keep a stack of days that are still waiting for a higher price. When today's price arrives, it resolves every waiting day whose price it beats.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions