Note π - might be a sister problem of π¦₯ Get Max Sum
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 k 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 k types of servers.
Complete the function getMaximumSum in the editor.
getMaximumSum has the following parameters:
int health[n]: the health of each serverint serverType[n]: the type of each serverint k: the maximum number of distinct types
Returns
long int: the maximum sum of health of the selected servers
Thanks a lot to Spike β our trusted authority! π₯°
health = [4, 5, 5, 6] serverType = [1, 2, 1, 2] k = 1 return = 11

k = 1, all selected servers must be the same type. The better option is to select type 2 servers. The maximum sum of health for type 2 servers is 5 + 6 = 11. Return 11.health = [1, 2, 3, 10, 10] serverType = [3, 3, 1, 2, 5] k = 2 return = 20
k = 2, the best option is to select servers of types 1 and 5. The maximum sum of health for these types is 2 + 3 + 10 = 15 for type 1 and 10 for type 5, which adds up to 20. Return 20.1 β€ k β€ n β€ 10^51 β€ health[i] β€ 10^91 β€ serverType[i] β€ n
- Count Promotional PeriodsOA Β· Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA Β· Seen Jun 2026
- Find Minimum CostOA Β· Seen Jun 2026
- Get Smallest Base SegmentOA Β· Seen Jun 2026
- Select Least Resource TasksOA Β· Seen Jun 2026
- Product Category Group SizesPHONE SCREEN Β· Seen May 2026
- Count Connected ComponentsPHONE SCREEN Β· Seen May 2026
public long getMaximumSum(int[] health, int[] serverType, int k) {
// write your code here
}