Find Minimum Time to Finish All Jobs II — LeetCode 2323 Python Solution

MediumLeetCode PremiumGreedyArraySorting
Problem
#2323
Pattern
Greedy
Reading time
2 min

The problem

You are given two 0-indexed integer arrays jobs and workers of equal length, where jobs[i] is the amount of time needed to complete the ith job, and workers[j] is the amount of time the jth worker can work each day. Each job should be assigned to exactly one worker, such that each worker completes exactly one job.

Example

Input
jobs = [5,2,4], workers = [1,7,5]
Output
2
Explanation
- Assign the 2nd worker to the 0th job. It takes them 1 day to finish the job.

Python solution

Python
class Solution:
    def minimumTime(self, jobs: List[int], workers: List[int]) -> int:
        jobs.sort()
        workers.sort()
        return max((a + b - 1) // b for a, b in zip(jobs, workers))

Complexity

MeasureComplexity
TimeO(n \log n)
SpaceO(\log n) auxiliary

Pattern: Greedy

Take the locally best option every time — when you can prove that never costs you later. LeetCode 2323. Find Minimum Time to Finish All Jobs II is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Greedy.

The greedy guide has the Python template for the pattern and the 346 LeetCode problems that use it.

Related problems

Frequently asked questions

How hard is LeetCode 2323. Find Minimum Time to Finish All Jobs II?
LeetCode 2323. Find Minimum Time to Finish All Jobs II is rated Medium on LeetCode.
What is the time complexity of LeetCode 2323. Find Minimum Time to Finish All Jobs II?
The Python solution on this page runs in O(n \log n).
What is the space complexity of LeetCode 2323. Find Minimum Time to Finish All Jobs II?
The Python solution on this page uses O(\log n) auxiliary space.
What topics does LeetCode 2323. Find Minimum Time to Finish All Jobs II cover?
LeetCode 2323. Find Minimum Time to Finish All Jobs II is tagged Greedy, Array and Sorting on LeetCode.
Is LeetCode 2323. Find Minimum Time to Finish All Jobs II a premium problem?
Yes. LeetCode 2323. Find Minimum Time to Finish All Jobs II is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview