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

Sign in to watch this lesson
Algorithms - Greedy · 4:07
To accept the most non-overlapping requests on one resource, sort by end time and take every request that starts no earlier than the last one taken ends: on [1,3] [2,5] [4,6] [6,8] [5,9] [8,10] that keeps four. We prove it with 'greedy stays ahead', settle whether touching endpoints conflict, and break the two tempting wrong keys (earliest start, shortest first) with counterexamples and a stress test on 5000 random inputs. Then the covering twin: fill the trading day [0, 10] with the fewest shifts by always jumping to the farthest reach.