Trains the technique from
LeetCode 765Couples Holding HandsThis 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 relay squad of n duos boards a shuttle with 2n seats in one straight row, numbered 0 to 2n - 1. The two athletes of duo k wear the bibs 2k and 2k + 1. The list seats records the boarding order: seats[i] is the bib of the athlete now sitting in seat i, and every bib appears exactly once.
Seats 2i and 2i + 1 form bench i. One move picks any two seats; the two athletes in them stand up and take each other's place. Return the smallest number of moves that leaves both athletes of every duo on the same bench.
Example 1
Bench 0 holds bibs 1 and 4, bench 1 holds 0 and 5, bench 2 holds 2 and 3. Swapping the athletes in seats 1 and 2 gives [1, 0, 4, 5, 2, 3], where bench 0 holds duo 0, bench 1 holds duo 2 and bench 2 holds duo 1, so one move is enough.
Example 2
Bench 0 already holds bibs 5 and 4, which are duo 2; bench 1 holds 1 and 0, duo 0; bench 2 holds 3 and 2, duo 1. Every duo is together, so no move is needed.
Example 3
Swapping seats 1 and 3 gives [0, 1, 4, 2, 3, 5], then swapping seats 3 and 5 gives [0, 1, 4, 5, 3, 2]. Bench 0 holds duo 0, bench 1 holds duo 2 and bench 2 holds duo 1, so two moves suffice.
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 min_swaps_couples(seats: list[int]) -> int:public int minSwapsCouples(int[] seats)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.