Skip to content
LC-0826 Medium LeetCode

826. Most Profit Assigning Work

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 56% Topics: Array, Two Pointers, Binary Search, Greedy, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(mlogm + nlogn), m is the number of workers,
#                        , n is the number of jobs
# Space: O(n)

class Solution(object):
    def maxProfitAssignment(self, difficulty, profit, worker):
        """
        :type difficulty: List[int]
        :type profit: List[int]
        :type worker: List[int]
        :rtype: int
        """
        jobs = zip(difficulty, profit)
        jobs.sort()
        worker.sort()
        result, i, max_profit = 0, 0, 0
        for ability in worker:
            while i < len(jobs) and jobs[i][0] <= ability:
                max_profit = max(max_profit, jobs[i][1])
                i += 1
            result += max_profit
        return result

Solution from kamyu104/LeetCode-Solutions · MIT