1723. Find Minimum Time to Finish All Jobs

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1723

class Solution:
    def minimumTimeRequired(self, jobs: List[int], k: int) -> int:
        def dfs(i):
            nonlocal res
            if i == len(jobs):
                res = min(res, max(cnt))
                return
            for j in range(k):
                if cnt[j] + jobs[i] >= res:
                    continue
                cnt[j] += jobs[i]
                dfs(i + 1)
                cnt[j] -= jobs[i]
                if cnt[j] == 0:
                    break

        cnt = [0] * k
        jobs.sort(reverse=True)
        res = inf
        dfs(0)
        return res