Ctrl K

One Job per Courier

Medium
There are n jobs and n couriers. Job i takes jobs[i] hours of work, and courier j can work hours[j] hours a day. Each job goes to exactly one courier, and each courier gets exactly one job. A courier works on their job every day until it is done, and all couriers work in parallel. Return the fewest days needed to finish every job under the best possible assignment.
Example 1
jobs=[10, 3, 8], hours=[2, 4, 3] → 3

Give the 10-hour job to the 4-hour courier (3 days), the 8-hour job to the 3-hour courier (3 days), and the 3-hour job to the 2-hour courier (2 days). Everyone is done in 3 days, and no faster plan exists: even the fastest courier needs 3 days for the 10-hour job.

Example 2
jobs=[6, 6], hours=[6, 1] → 6

One courier must take a 6-hour job at 1 hour a day, which takes 6 days.

Example 3
jobs=[1], hours=[100] → 1
Constraints
  • 1 ≤ n = len(jobs) = len(hours) ≤ 10⁵
  • 1 ≤ jobs[i], hours[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBiggest Number From Pieces MediumStudios for Recording Sessions MediumLow, High, Low MediumStrictly Low, High, Low MediumFewest Meetings to Cancel Medium
loading Python…
Input
jobs=[10, 3, 8], hours=[2, 4, 3]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.