22/40
Part 5 of 8 · Merging and schedulingLearn and do

Calls that arrive out of order have to be replayed in time order

The room loop's first rule says start order, and the loop has to sort for it. Meetings arrive in the order they were booked, but the loop must see them in the order they happen. Feed them in as given, and [(5, 9), (1, 3), (2, 6)] needs 3 rooms instead of 2. The meeting from 5 to 9 went in first, so it's counted as holding a room at 1 and at 2, before it starts.

The practice problem's calls arrive out of order too, and there it changes who pays. Here are two credits of 10 each, and two spends. The spend at time 4 is recorded first, and the spend at time 2 after it:

CreditUsable
A, 10from 0 until 20
B, 10from 3, and never expires

The spends are 5 at time 2, recorded second, and 10 at time 4, recorded first.

Predict

A and B hold 10 each. A spend of 10 at time 4 is recorded before a spend of 5 at time 2. Applied as they arrive, how much is left unpaid?

Pick an answer above to see the rest