The first shipment that covers it
transcript
A warehouse receives shipments, one after another. A customer waits for a number of units. Which shipment is the first to cover the order?
Keep the running total after each shipment. The totals never go down, even for an empty shipment. So a binary search works on them.
The totals are zero, four, four, nine, twelve. An order for four is covered at position one. Not at position two, which comes later.
Equal totals can repeat. Keep looking left when one qualifies. Return the smallest index.
Low starts at zero. High starts at the length. A position past the end is allowed.
No total reaches thirteen. Return minus one, not a position.
In the interview, ask what counts as covered. Ask what equal totals mean. And ask what no answer should return.
Each order is one binary search. Each search is logarithmic. The list is shared by all orders.
First position that reaches it. Past the end means minus one. Full breakdown in the lecture.