Design a function to calculate total courier pay from a set of delivery orders.
Assume time is represented as integer minutes, and intervals are half-open: an order active from minute start to minute end contributes on [start, end).
Base version
Each order has:
There is a global rate paid per minute.
For any minute in which an order is active, that order earns rate * k, where k is the number of orders active in that same minute. In other words, if k orders overlap during a minute, the total pay contributed by that minute is k * k * rate.
Implement a function that returns the total pay across all orders.
The interviewer may ask you to define reasonable input/output structures yourself, explain your chosen data structures, analyze time and space complexity, and write meaningful test cases.
Follow-up 1
Now each order may also include:
The interval [arrived_at, picked_up_at) is store-wait time. A store-wait minute is paid only for that order itself:
-
it must not increase the multiplier for any other order
-
other orders must not increase its multiplier
Update the design to support this rule.
Follow-up 2
During configurable peak-hour intervals, the per-minute rate is doubled.
Explain how you would extend your solution to support this efficiently.