Problem · Array

Minimum Processing Speed with Multiple Riders

Learn this problem
HardDoorDash logoDoorDashFULLTIMEONSITE INTERVIEW

Problem statement

Assign an ordered sequence of indivisible order workloads to at most riders riders. Each rider receives one contiguous subsequence, and every rider has at most hoursPerRider whole hours.

At a shared positive integer speed k, workload w takes ceil(w / k) hours. A rider processes assigned orders in order, and unused time in an order's final hour is lost.

Return the minimum speed for which a left-to-right contiguous assignment uses at most riders riders.

Function

minimumMultiRiderSpeed(workloads: int[], riders: int, hoursPerRider: int) → int

Examples

Example 1

workloads = [3,6,7,11]riders = 2hoursPerRider = 4return = 6

At speed 6 the required hours are [1,1,2,2]. One rider takes the first three orders in four hours and the other takes the last order. Speed 5 needs three contiguous groups.

Example 2

workloads = [8,8,8]riders = 3hoursPerRider = 1return = 8

Each rider must finish one order in one hour.

Constraints

  • workloads is non-empty and every workload is positive.
  • riders and hoursPerRider are positive.
  • riders does not exceed the number of workloads.
  • riders * hoursPerRider is at least the number of workloads, so a feasible speed always exists.

More DoorDash problems

drafts saved locally
public int minimumMultiRiderSpeed(int[] workloads, int riders, int hoursPerRider) {
    // TODO: binary-search the minimum speed with contiguous greedy packing.
}
workloads[3,6,7,11]
riders2
hoursPerRider4
expected6
checking account