A delivery platform has a service that can return all orders delivered by a courier.
You are given:
-
courierId
: the courier's identifier.
-
ratePerMinute
: the courier's pay rate.
-
A service method such as
getOrders(courierId)
that returns a list of orders. Each order has:
-
startTime
: when the courier started working on that order.
-
endTime
: when the courier completed that order.
Assume times are represented as integer minutes and endTime >= startTime.
Implement a function to compute how much the courier should be paid.
Base requirement:
-
Each order is paid independently.
-
Total pay is the sum of
(endTime - startTime) * ratePerMinute
across all orders.
Follow-up:
-
Couriers may handle multiple orders at the same time, so order intervals can overlap.
-
Implement a second version that computes pay based on actual active working time, where overlapping intervals are counted only once.
-
For example, if the courier has orders
[10, 20]
and
[15, 25]
, the active working time is
15
minutes, not
20
minutes.