Solution: Most Profit Assigning Work
Let's solve the Most Profit Assigning Work problem using the Sort and Search pattern.
We'll cover the following...
Statement
You are given n jobs and m workers, represented by three arrays: difficulty, profit, and worker.
difficulty[i]andprofit[i]represent the difficulty level and profit of thei-thjob.worker[j]represents the maximum difficulty level thej-thworker 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
Return the maximum total profit achievable by assigning jobs to workers optimally.
Constraints:
n == difficulty.lengthn == profit.lengthm == worker.lengthn,m...