Trains the technique from
LeetCode 2130Maximum Twin Sum of a Linked ListThis 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 chain of wagons runs from front to back and holds an even number of them. Counting from zero, wagon i is coupled with wagon n - 1 - i, so the front wagon pairs with the back one, the second with the second from the back, and so on.
Because the harness passes plain JSON, the chain reaches you as chain, listing the loads in order from the front wagon.
A couple's weight is the sum of its two wagons' loads. Return the largest weight any couple carries.
Example 1
The two outer wagons couple for a weight of 2 and the two inner ones for 200.
Example 2
Every couple weighs 7: the first with the last, the second with the fifth and the third with the fourth.
Example 3
The chain holds a single couple, so its weight is the answer.
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 pair_sum(chain: list[int]) -> int:public int pairSum(int[] chain)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.