Back to Greedy
Course Practice
Medium

Maximize Profit From Task Assignment

LAB

Assign workers to jobs they can do. Each job has difficulty and profit; return maximum total profit with each worker taking one job.

EXAMPLES

Example 1
Input
{
  "difficulty": [
    2,
    4,
    6,
    8,
    10
  ],
  "profit": [
    10,
    20,
    30,
    40,
    50
  ],
  "worker": [
    4,
    5,
    6,
    7
  ]
}

Output
100

FUNCTION SHAPE

difficulty: intArrayprofit: intArrayworker: intArrayint
SOLUTION NOTE

This is a fairly simple problem. Just handle it with greedy intuition. Obviously you want to pair the worker with the highest profit task they can do.

Open on LeetCode
00:00
2 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.