Problem · Array

Minimum Single-Rider Processing Speed

Learn this problem
MediumDoorDash logoDoorDashFULLTIMEONSITE INTERVIEW

Problem statement

A rider must finish a sequence of order workloads within hours whole hours. At a positive integer speed k, an order with workload w takes ceil(w / k) hours.

  • The rider works on only one order during an hour.
  • Unused capacity in an order's final hour is lost.

Return the minimum positive integer speed that finishes every order within hours.

Function

minimumRiderSpeed(workloads: int[], hours: int) → int

Examples

Example 1

workloads = [3,6,7,11]hours = 8return = 4

At speed 4 the orders take 1, 2, 2, and 3 hours, totaling 8. Speed 3 requires 10 hours.

Example 2

workloads = [30,11,23,4,20]hours = 5return = 30

There are five orders and five hours, so every order must finish in one hour.

Constraints

  • workloads is non-empty and every workload is positive.
  • hours is at least the number of workloads.

More DoorDash problems

drafts saved locally
public int minimumRiderSpeed(int[] workloads, int hours) {
    // TODO: return the minimum feasible positive speed.
}
workloads[3,6,7,11]
hours8
expected4
checking account