Ctrl K

Strength of the Weaker Partner

Easy
A coach is splitting players into pairs for a tournament. Their ratings are given in ratings; there is an even number of players, and each one goes into exactly one pair. A team plays at the level of its weaker member, so a pair's strength is the smaller of its two ratings. Split the players into pairs so that the total strength of all pairs is as large as possible, and return that total.
Example 1
ratings=[7, 2, 5, 1] → 6

The best split is (1, 2) and (5, 7): team strengths 1 and 5, total 6. Pairing (1, 7) and (2, 5) would give only 1 + 2 = 3.

Example 2
ratings=[-3, 4, 4, 0, -3, 9] → 1

Pairs (-3, -3), (0, 4), (4, 9) give -3 + 0 + 4 = 1.

Constraints
  • 2 ≤ length of ratings ≤ 2·10⁴, and the length is even
  • -10⁴ ≤ ratings[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsScooters to Chargers EasyMost Snacks on a Budget MediumOne Rook per Line MediumCake Slices for Guests EasyTriangle From Sticks Easy
loading Python…
Input
ratings=[7, 2, 5, 1]
Expected
6

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