Two interns at HackerRank are teamed up to complete a total of
n
tasks. Each tas to be completed by either of the two interns. Both interns have their reward point defined, where the first intern gains reward_1[i] points for completing the
i th task, while the second intern gains reward_2[i] points for completing the
f th task. Since the interns work as a team, they wish to maximize the total reward points gained by both of them combined. Find the maximum combined reward points tha can be gained if the first intern has to complete
k
tasks, and the second intern completes the remaining tasks. Note: The
k
tasks completed by the first intern could be any amongst the
n
tasks. Example Consider
n=5
, reward_1
1=[5,4,3,2,1]
, reward_
2=[1,2,3,4,5]
and
k=3
. Intern 1 has to complete 3 tasks, while intern 2 has to complete the remaining 2 tasks. In order to maximize the points gained, intern 1 completes the first 3 tasks, while intern 2 completes the last 2 tasks. Total reward points gained
=5+4+3
(from intern 1
)+4+5
(from intern 2 )
=21
, which is the maximum possible. Thus, the answer is
21.
Function Description: Complete the function getMaximumRewardPoints in the editor below. getMaximumRewardPoints has the following parameters: int
k
: the number of tasks that have to be completed by intern 1 int reward_1[n]: the reward points earned by intern 1 for each task int reward_2[n]: the reward points earned by intern 2 for each task Returns int: the maximum possible combined reward points when intern 1 completes exactly
k
tasks Constraints: -
1≤n≤10 5
-
0≤k≤n
-
1≤
reward_1[i] 104 -
1≤
reward_2[i]
≤10 4
I*
⋆
Complete the 'getMaximumRewardPoints' function below. * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER
k
* 2. INTEGER_ARRAY reward_1 * 3. INTEGER_ARRAY reward_2 * public static int getMaximumRewardPoints (int
k
List reward 1 , List reward 2) \{ // Write your code here \} 3 public class Solution
{⋯
Sample Case 0 Sample Input For Custom Testing Sample Output 8 Explanation Intern 1 has to complete 3 tasks, while intern 2 has to complete the remaining 1 task. The reward points for each task are the same for both the interns, so any tasks can be picked up by either intern. Total reward points
=1+2+3+2=8
. 10
11#
12 # Complete the 'getMaximumRewardPoints' function below. 13 # 14 # The function is expected to return an INTEGER. 15 # The function accepts following parameters: 16 # 1. INTEGER
k
17 # 2. INTEGER_ARRAY reward_1 18 # 3. INTEGER_ARRAY reward_2
19#
21 def getMaximumRewardPoints(k, reward_1, reward_2): 22 # Write your code here
24>
if name
=−1