The Most Profit Assigning Work problem gives you a list of jobs (each with a difficulty and profit) and a list of workers (each with a maximum ability level). Each worker can complete any job with difficulty ≤ their ability, and earns the job's profit. A job can be assigned to multiple workers. Maximize the total profit across all workers. This Most Profit Assigning Work coding problem is solved elegantly with sorting and greedy matching.
NetEase, Microsoft, Meta, Amazon, TikTok, and Google ask this because it tests the ability to match workers to the best possible job using sorting and a two-pointer or binary search approach. The array, sorting, two pointers, binary search, and greedy interview pattern is fully represented. The key insight — precomputing the best profit up to each difficulty level — separates clean solutions from brute-force ones.
Sort both + prefix max + two pointers or binary search. Sort jobs by difficulty. Build a prefix max array of profits (best profit achievable for difficulty ≤ i). Sort workers by ability. For each worker (in ascending ability order), advance through jobs using a pointer and track the maximum profit seen so far. Each worker earns the maximum profit of all jobs they can handle.
Jobs: [(2,100),(1,200),(3,300)]. Workers: [3,1,2]. Sort jobs by difficulty: [(1,200),(2,100),(3,300)]. Prefix max profits: [200,200,300]. Sort workers: [1,2,3].
"Assign best matching resource to each query" problems always benefit from sorting both lists and using a two-pointer sweep with a running maximum. The prefix max pattern — best[i] = max(best[i-1], profit[i]) — converts "best up to difficulty d" from O(d) to O(1). This pattern generalizes to any problem where you want the best item satisfying a threshold, after sorting. Practice it with "assign tasks to workers" variants using different constraints.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Valid Triangle Number | Medium | Solve | |
| Number of Subsequences That Satisfy the Given Sum Condition | Medium | Solve | |
| Friends Of Appropriate Ages | Medium | Solve | |
| Maximum Matching of Players With Trainers | Medium | Solve | |
| 3Sum Smaller | Medium | Solve |