Maximize Chef Assignment Profit
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates skill in array manipulation, data preprocessing, and algorithmic optimization for matching resources to tasks and aggregating profits.
Part 1: Maximum Total Profit from Chef Assignments
Constraints
- 0 <= len(chefSkill) <= 100000
- 0 <= len(dishDifficulty) == len(dishProfit) <= 100000
- 0 <= chefSkill[i], dishDifficulty[j], dishProfit[j] <= 1000000000
- The total profit may exceed 32-bit integer range.
Examples
Input: ([1, 2, 3], [1, 2, 3], [1, 2, 3])
Expected Output: 6
Explanation: Each chef can cook the dish with the matching difficulty, so the total is 1 + 2 + 3 = 6.
Input: ([5, 5, 5], [2, 4], [10, 50])
Expected Output: 150
Explanation: All three chefs can cook the difficulty-4 dish worth 50 profit, and the same dish can be reused.
Hints
- If you sort dishes by difficulty, you can track the best profit seen so far as difficulty increases.
- If you also sort the chefs by skill, you can scan through the dishes only once.
Part 2: Build Best Profit by Difficulty Array
Constraints
- 0 <= len(dishDifficulty) == len(dishProfit) <= 100000
- 0 <= dishDifficulty[j] <= 200000
- 0 <= dishProfit[j] <= 1000000000
Examples
Input: ([1, 2, 3], [1, 2, 3])
Expected Output: [0, 1, 2, 3]
Explanation: At each difficulty, the best available profit is the largest profit among dishes up to that difficulty.
Input: ([2, 4, 2, 5], [10, 20, 15, 5])
Expected Output: [0, 0, 15, 15, 20, 20]
Explanation: Difficulty 2 has two dishes, so keep the better profit 15. Then apply prefix maxima.
Hints
- First store the best profit for each exact difficulty value.
- Then sweep from left to right and turn the array into a prefix maximum array.