Search⌘ K
AI Features

Solution: Most Profit Assigning Work

Let's solve the Most Profit Assigning Work problem using the Sort and Search pattern.

Statement

You are given n jobs and m workers, represented by three arrays: difficulty, profit, and worker.

  • difficulty[i] and profit[i] represent the difficulty level and profit of the i-th job.

  • worker[j] represents the maximum difficulty level the j-th worker can handle.

A worker can complete a job only if the job’s difficulty is less than or equal to that worker’s ability. Each worker can be assigned at most one job, but the same job can be completed by multiple workers.

If a worker cannot complete any job, they contribute 00profit.

Return the maximum total profit achievable by assigning jobs to workers optimally.

Constraints:

  • n == difficulty.length

  • n == profit.length

  • m == worker.length

  • 11 \leq n, m ...