Trains the technique from
LeetCode 561Array PartitionThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rowing club is drawing up doubles for a regatta. margins carries one entry per member: the number of seconds by which that member beats the club standard over the course, so a member who is slower than the standard has a negative entry. The club has an even number of members and every one of them has to be placed in exactly one double.
A double is credited with the lesser of its two members' margins, since a crew can only go as fast as its slower half. The club's score for a set of doubles is the total credited across all of them.
Return the highest score the club can reach, over every way of splitting the members into doubles.
Example 1
Rowing the doubles as (1, 5) and (5, 9) records margins of 1 and 5.
Example 2
Rowing (-9, -7) as one double and (-4, -2) as the other records -9 and -4.
Example 3
The doubles (-30, -30), (7, 12) and (12, 40) record -30, 7 and 12.
Example 4
Two members make up the only double, and the crew is held to the slower of them.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_pair_total(margins: list[int]) -> int:public int bestPairTotal(int[] margins)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.