Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 36s1 days 16 hours 1 minutes 36 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 36s1 days 16 hours 1 minutes 36 seconds.

Sign in to watch this lesson
Advanced - Greedy and Scheduling · 3:57
A regret greedy takes the locally best move but leaves a token in a heap, so a later, better option can undo it at its marginal cost. With one share per day and unlimited holdings, a min-heap that pushes each sale's price twice (a regret token and a possible buy) finds the maximum profit. The same heap-as-budget pattern solves Furthest Building, Refueling Stops and IPO, and Huffman merging (always merge the two smallest) minimizes total merge cost.