How to maximize rewards with exactly k tasks
MathWorksSoftware Engineer · Technical ScreenLast updated
This Coding & Algorithms question evaluates a candidate's ability to perform combinatorial optimization and benefit-based assignment reasoning on arrays, testing algorithm design, complexity-aware implementation, and quantitative decision-making in constrained assignment problems.
You are assigning n independent tasks to two interns.
- Each task must be done by exactly one intern.
- If intern 1 does task i, you earn
reward1[i]points. - If intern 2 does task i, you earn
reward2[i]points. - Intern 1 must be assigned exactly
ktasks; intern 2 gets the remainingn - ktasks. - Tasks can be assigned in any order (no contiguity requirement).
Goal: Return the maximum total points achievable.
Input
reward1: integer array of lengthnreward2: integer array of lengthnk: integer (0 ≤ k ≤ n)
Output
- An integer: the maximum possible total reward.
Notes / Expected Complexity
Design an algorithm that works efficiently for large n (e.g., up to 10^5).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.