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

Sign in to watch this lesson
Algorithms - Greedy · 4:00
Most greedy algorithms start by sorting and then sweep once, proved by an invariant that keeps greedy ahead. We find the smallest amount coins [1, 2, 2, 7, 9] can't pay by growing a reach of payable amounts (1, 3, 5, then a gap at 6), pair Ferris-wheel riders [2, 3, 7, 8] lightest-with-heaviest into two gondolas, and hand out tickets from a std::multiset with prev(upper_bound(x)), erasing by iterator because erase by value removes every copy.