Push the edge farthest
transcript
Five traffic spikes hit a service. You hold a list of cache windows. Cover every spike with the fewest windows. One rule decides it. Here it is.
Keep one number, called the edge. Everything before the edge is settled. Everything after the edge is still open. The edge only ever moves forward.
Look only at windows that start in time. A window that starts later cannot help yet. Among the rest, find the farthest end.
The spikes are two, three, seven, eight and twelve. At spike two, the best end is four. At spike seven, the best end is nine. At spike twelve, the best end is thirteen. Three windows cover all five spikes.
The farthest end moves the edge the most. It leaves the next step the most options. Earliest end first costs an extra window here.
Keep an edge. Take the farthest end that starts in time. If nothing reaches, the answer is minus one. Full breakdown in the lecture.