Find Max Health Sum
Updated
Problem statement
You are given n servers. Server i has health health[i] and type serverType[i].
Select servers whose type values contain at most m distinct types. Return the maximum possible sum of the selected servers' health values.
Function
findMaxHealthSum(health: int[], serverType: int[], m: int) → longExamples
Example 1
health = [4, 5, 5, 6]serverType = [1, 2, 1, 2]m = 1return = 11
Type 1 has total health 4 + 5 = 9, while type 2 has total health 5 + 6 = 11. Since m = 1, select type 2 and return 11.
Constraints
1 ≤ m ≤ n ≤ 10^5health.length = serverType.length = n1 ≤ health[i] ≤ 10^91 ≤ serverType[i] ≤ n
More Amazon interview questions
- Get Smallest Base SegmentOA · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- 3SumPHONE SCREEN · Seen Nov 2026
- Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Nickname-Constrained GroupingZoox · ONSITE INTERVIEW
- Partition Into K-Size Consecutive GroupsDream11 · ONSITE INTERVIEWDream11 interview questions
- Find the Original Array From a Doubled ArrayGoogle · PHONE SCREENGoogle interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
Amazon interview experiences
- Amazon SWE OA with AI Coding: 1 Experience
- Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
- Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
- Amazon BIE Intern SQL and Interview Questions: 17 Experiences
- Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
- Amazon SDE II (L5) Interview Questions: 5 Experiences