Assign Each Worker Its Best Feasible Reusable Job

Quick Overview

Assign Each Worker Its Best Feasible Reusable Job. Job i has difficulty[i] and profit[i]. Worker j can do any job whose difficulty is at most worker[j], and can receive at most one assignment.

Assign Each Worker Its Best Feasible Reusable Job

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Job i has difficulty[i] and profit[i]. Worker j can do any job whose difficulty is at most worker[j], and can receive at most one assignment. A job may be assigned to any number of workers. Unassigned workers contribute zero. Return the largest total profit. ```cpp class Solution { public: int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker); }; ``` ### Examples **Example 1:** ```text difficulty = [2,5], profit = [7,12], worker = [1,3,5] Output: 19 Explanation: The workers contribute0,7,12. ``` **Example 2:** ```text difficulty = [1,3], profit = [9,4], worker = [3,3] Output: 18 Explanation: Both workers choose the easier but more profitable first job. ``` ### Constraints - Job count n equals both difficulty and profit lengths; worker count is m. - Both n and m lie in [1,10000]. - Difficulties, profits and abilities lie in [1,100000]. ### Contract considerations Keep reusable jobs and at-most-one assignment per worker. ```hint Read the boundary condition Do workers compete for limited copies of a job? ``` ### Boundary reminders Keep reusable jobs and at-most-one assignment per worker.

Overview: Assign Each Worker Its Best Feasible Reusable Job. Job i has difficulty[i] and profit[i]. Worker j can do any job whose difficulty is at most worker[j], and can receive at most one assignment.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Job i has difficulty[i] and profit[i]. Worker j can do any job whose difficulty is at most worker[j], and can receive at most one assignment. A job may be assigned to any number of workers. Unassigned workers contribute zero. Return the largest total profit.

class Solution {
public:
    int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker);
};

Examples

Example 1:

difficulty = [2,5], profit = [7,12], worker = [1,3,5]
Output: 19
Explanation: The workers contribute0,7,12.

Example 2:

difficulty = [1,3], profit = [9,4], worker = [3,3]
Output: 18
Explanation: Both workers choose the easier but more profitable first job.

Constraints

  • Job count n equals both difficulty and profit lengths; worker count is m.
  • Both n and m lie in [1,10000].
  • Difficulties, profits and abilities lie in [1,100000].

Contract considerations

Keep reusable jobs and at-most-one assignment per worker.

Boundary reminders

Keep reusable jobs and at-most-one assignment per worker.