How to maximize rewards with exactly k tasks
Company: MathWorks
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
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 `k` tasks**; intern 2 gets the remaining `n - k` tasks.
- Tasks can be assigned in any order (no contiguity requirement).
**Goal:** Return the **maximum total points** achievable.
### Input
- `reward1`: integer array of length `n`
- `reward2`: integer array of length `n`
- `k`: 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`).
Quick Answer: 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.
Assign exactly k tasks to intern 1 and the rest to intern 2 to maximize total reward.
Examples
Input: ([10, 20, 30], [5, 50, 5], 2)
Expected Output: 90
Explanation: Choose largest deltas.
Input: ([1, 2], [10, 20], 0)
Expected Output: 30
Explanation: All intern 2.
Hints
- Start with all tasks assigned to intern 2, then choose the k largest reward differences.