Problem · Array

Maximum Reward Points

Learn this problem
MediumMicrosoftNEW GRADINTERNOA
See Microsoft hiring insights

Problem statement

Two interns are assigned to complete a total of n tasks. Each task must be completed by exactly one of them. For task i, the first intern earns reward_1[i] points and the second intern earns reward_2[i] points.

The first intern must complete exactly k tasks, which may be any k of the n tasks. The second intern completes the remaining tasks. Return the maximum possible combined reward points.

Function

getMaximumRewardPoints(k: int, reward_1: int[], reward_2: int[]) → int

Examples

Example 1

k = 3reward_1 = [5, 4, 3, 2, 1]reward_2 = [1, 2, 3, 4, 5]return = 21

The first intern completes the first three tasks and earns 5 + 4 + 3 points. The second intern completes the remaining two tasks and earns 4 + 5 points. Their combined reward is 5 + 4 + 3 + 4 + 5 = 21, which is the maximum possible.

Constraints

  • 1 ≤ n ≤ 10^5
  • 0 ≤ k ≤ n
  • 1 ≤ reward_1[i] ≤ 10^4

More Microsoft problems

drafts saved locally
public int getMaximumRewardPoints(int k, int[] reward_1, int[] reward_2) {
  // write your code here
}
k3
reward_1[5, 4, 3, 2, 1]
reward_2[1, 2, 3, 4, 5]
expected21
checking account