FunctionRacerProblemsRace

Array Partition

EasyGreedyPython, JavaScript, TypeScript, Java, C++

nums has an even number of items. Split it into pairs (every item used exactly once). The score of a pair is its smaller number, and the score of a split is the sum of its pair scores.

Return the largest score you can get from any split.

Example 1

nums [1,4,3,2]
returns 4

Pair (1,2) and (3,4): 1 + 3 = 4.

Example 2

nums [6,2,6,5,1,2]
returns 9

Pair (1,2), (2,5), (6,6): 1 + 2 + 6 = 9.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems