Task Completion
Updated
Problem statement
Two interns at HackerRank are teamed up to complete a total of n tasks. Each task is to be completed by either of the two interns. Both interns have their reward points defined, where the first intern gains reward_1[i] points for completing the ithth task, while the second intern gains reward_2[i] points for completing the ithth 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 that 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.
Function
getMaximumRewardPoints(k: int, reward_1: int[], reward_2: int[]) → int
Complete the function getMaximumRewardPoints in the editor.
getMaximumRewardPoints has the following parameters:
- 1.
int k: the number of tasks that have to be completed by intern 1 - 2.
int reward_1[n]: the reward points earned by intern 1 for each task - 3.
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
Examples
Example 1
k = 3reward_1 = [5, 4, 3, 2, 1]reward_2 = [1, 2, 3, 4, 5]return = 21Intern 1 has to complete 3 tasks, while intern 2 has to complete the remaining 2 tasks. 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.
Example 2
k = 2reward_1 = [2, 3, 4, 2]reward_2 = [1, 1, 1, 1]return = 9Intern 1 has to complete 2 tasks, while intern 2 has to complete the remaining 2 tasks. In order to maximize the total reward points, intern 1 completes the second and third tasks, while intern 2 completes the first and fourth tasks. Total reward points gained = 4 + 3 (from intern 1) + 1 + 1 (from intern 2) = 9.
Constraints
- 1 ≤
n≤ 105 - 0 ≤
k≤n - 1 ≤
reward_1[j]≤ 104 - 1 ≤
reward_2[j]≤ 104
More MathWorks interview questions
- Earliest Time to Schedule a MeetingOA · Seen Nov 2026
- Minimum Cost to Serve Requests on a RingOA · Seen Nov 2026
- Minimum Tree Diameter After Removing K LeavesOA · Seen Nov 2026
- Cities on Shortest Delivery RoutesOA · Seen Nov 2026
- Repeated Mirror XOROA · Seen Nov 2026
- Beautiful ArrangementONSITE INTERVIEW · Seen Jul 2026
- Find Minimum Cost to Remove Array ElementsONSITE INTERVIEW · Seen Jul 2026
- Group Shifted StringsONSITE INTERVIEW · Seen Jul 2026
- Longest Valid ParenthesesONSITE INTERVIEW · Seen Jul 2026
- Balancing TeamsOA · Seen Nov 2025
Similar questions at other companies
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Maximize Center A Package BenefitAmazon · OA
- EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions