Problem · Array
Find Max Health Sum
Learn this problemProblem statement
Amazon is building a new data center with n servers of different types. The health and type of each server are represented in the arrays health and serverType. The developers need to build a server facility with a maximum of m distinct types of servers and the sum of their health should be maximized.
Given arrays health and serverType, find the maximum sum of the health for up to m types of servers.
Function
findMaxHealthSum(health: int[], serverType: int[], m: int) → long
Complete the function findMaxHealthSum in the editor below.
findMaxHealthSum has the following parameters:
- 1.
int health[n]: the health of each server - 2.
int serverType[n]: the type of each server - 3.
m: the maximum number of distinct types
Returns
long int: the maximum sum of health of the selected servers
Examples
Example 1
health = [4, 5, 5, 6]serverType = [1, 2, 1, 2]m = 1return = 11
Since
m = 1, all selected servers must be the same type. The better option is to select type 2 servers. Return 11.Constraints
1 ≤ m ≤ n ≤ 10^51 ≤ health[i] ≤ 10^91 ≤ serverType[i] ≤ n
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026