Ctrl K

A Team and Its Weakest Link

Medium
A club has n players. Player i has skill skill[i] and stamina stamina[i]. You must form a team of exactly team_size distinct players. The team's score is the total skill of its members multiplied by the smallest stamina among them: a team lasts only as long as its weakest member. Return the highest possible score.
Example 1
skill=[5, 1, 4, 6], stamina=[3, 8, 2, 4], team_size=2 → 33

Players 0 and 3 give (5 + 6) · min(3, 4) = 33. Adding player 2 would drag the multiplier down to 2.

Example 2
skill=[2, 9, 3], stamina=[10, 1, 10], team_size=1 → 30

Solo players score 20, 9 and 30, so player 2 is best.

Example 3
skill=[3, 3, 3], stamina=[7, 0, 5], team_size=3 → 0

Everyone must play, and player 1 has stamina 0, so the score is 0.

Constraints
  • 1 ≤ n = len(skill) = len(stamina) ≤ 10⁵
  • 0 ≤ skill[i], stamina[i] ≤ 10⁵
  • 1 ≤ team_size ≤ n
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStudios for Recording Sessions MediumJobs With a Cooldown MediumSpread Out the Labels MediumCross Out Half the List MediumOne Event per Day Medium
loading Python…
Input
skill=[5, 1, 4, 6], stamina=[3, 8, 2, 4], team_size=2
Expected
33

Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.