Maximum combination health of AI modules
I was asked this
No reports yet. Sign in to say where you were asked it.
A lab is assembling an AI system from n candidate modules. Module i has a health health[i] (how much it contributes) and a stability stability[i] (how reliable it is). Both are non-negative integers.
You may pick a combination of at least 1 and at most k distinct modules. A combination is only as reliable as its weakest member, so its score is:
combination_health = (sum of health of chosen modules) * (minimum stability among chosen modules)
Implement:
def max_combination_health(health: list[int], stability: list[int], k: int) -> int:
...
Return the largest possible combination_health. Return 0 if n == 0 or k <= 0.
Constraints
-
0 <= n <= 10^5,len(health) == len(stability) 0 <= health[i], stability[i] <= 10^5-
0 <= k;kmay exceedn
Example 1
health = [4, 9, 2, 6]
stability = [5, 2, 8, 4]
k = 2
-> 40
Choose modules 0 and 3: (4 + 6) * min(5, 4) = 40. Module 1 has the most health, but its stability of 2 pulls any combination containing it down to at most (9 + 6) * 2 = 30.
Example 2
health = [10, 10, 10]
stability = [1, 1, 100]
k = 3
-> 1000
Module 2 alone scores 10 * 100 = 1000, more than taking all three (30 * 1 = 30).
Aim for better than trying every subset.
Reconstructed from the reported question; details may differ from what interviewers ask.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
