Seconds over the stock
transcript
A flash sale holds units for checkout. It can accept more reservations than it has units. For how many seconds was it oversold?
A start takes units. An end returns them. Sort all events by time.
The stock is three units. The total is four, then six, over the stock. The last stretch holds two.
Take the time since the last event. It was spent at the current total. Add it if the total is over.
One second was spent at four units. Two seconds were spent at six units. That makes three oversold seconds.
Add the time between events. Do not count the events themselves.
In the interview, say what a reservation holds. Say when a reservation ends. And say what counts as over.
A reservation ends before its end second. Touching reservations do not overlap. There is no overlap at that second.
Sort the events. Add the time spent over. Full breakdown in the lecture.