Find the minimum positive integer processing speed that completes indivisible delivery orders within a whole-hour deadline, or report impossibility when the available hours are insufficient.
## Problem
A delivery worker has `hours` whole hours to finish `n` orders. Order `i` has `work[i]` units. If the worker's integer processing speed is `speed` units per hour, that order consumes `ceil(work[i] / speed)` hours.
The worker can process only one order during an hour. If an order finishes before the hour ends, the unused portion of that hour cannot be applied to another order. Return the minimum positive speed that finishes all orders within `hours`.
### Function Contract
Implement `minimumDeliverySpeed(work, hours)` and return an integer. Return `-1` when completion is impossible even at unlimited speed.
### Constraints & Assumptions
- `0 <= len(work) <= 200,000`.
- `1 <= work[i] <= 10^9`.
- `0 <= hours <= 10^14`.
- At least one whole hour is required for each order, so a nonempty input is impossible when `hours < len(work)`.
- An empty order list requires no work; return `0`.
- Summed hours fit in a signed 64-bit integer.
### Clarifying Questions to Ask
- Can work from two orders share one hour? No.
- Why is the maximum order size a sufficient upper bound? At that speed every order takes exactly one hour.
- Is speed restricted to an integer? Yes.
- How should ceiling division avoid floating-point error? Use integer arithmetic.
```hint Search a monotone answer
If a speed is fast enough, every larger speed is also fast enough. Test a candidate by summing each order's ceiling-divided hours.
```
### Examples
- `work = [3, 6, 7, 11]`, `hours = 8` returns `4`.
- `work = [30, 11, 23, 4, 20]`, `hours = 5` returns `30`.
- `work = [5, 9]`, `hours = 1` returns `-1`.
- `work = []`, `hours = 0` returns `0`.
### Evaluation Focus
- Uses the per-order ceiling rather than dividing total work by total time.
- Chooses valid binary-search bounds and returns the first feasible speed.
- Avoids overflow in ceiling division and stops a feasibility sum once it exceeds `hours`.
- Runs in `O(n log max(work))` time and `O(1)` auxiliary space.
### Extensions to Discuss
1. Why does requiring a priority order not change the single-worker feasibility sum?
2. How would feasibility change with several workers and indivisible orders?
3. What if a worker could switch between orders within an hour?
Quick Answer: Find the minimum positive integer processing speed that completes indivisible delivery orders within a whole-hour deadline, or report impossibility when the available hours are insufficient.
A delivery worker has hours whole hours to finish n orders. Order i has work[i] units. If the worker's integer processing speed is speed units per hour, that order consumes ceil(work[i] / speed) hours.
The worker can process only one order during an hour. If an order finishes before the hour ends, the unused portion of that hour cannot be applied to another order. Return the minimum positive speed that finishes all orders within hours.
Function Contract
Implement minimumDeliverySpeed(work, hours) and return an integer. Return -1 when completion is impossible even at unlimited speed.
Constraints & Assumptions
0 <= len(work) <= 200,000
.
1 <= work[i] <= 10^9
.
0 <= hours <= 10^14
.
At least one whole hour is required for each order, so a nonempty input is impossible when
hours < len(work)
.
An empty order list requires no work; return
0
.
Summed hours fit in a signed 64-bit integer.
Clarifying Questions to Ask Guidance
Can work from two orders share one hour? No.
Why is the maximum order size a sufficient upper bound? At that speed every order takes exactly one hour.
Is speed restricted to an integer? Yes.
How should ceiling division avoid floating-point error? Use integer arithmetic.