AMC 10 Step by Step

2024 AMC 10A Problem 6

P1-10~2 minPrint

What is the minimum number of successive swaps of adjacent letters in the string ABCDEFABCDEF that are needed to change the string to FEDCBA?FEDCBA? (For example, 33 swaps are required to change ABCABC to CBA;CBA; one such sequence of swaps is ABC→BAC→BCA→CBA.ABC\to BAC\to BCA\to CBA. )

Log in to save your progress.
Show solution without answering

Key insight

All 15 pairs of letters must switch order, and one swap of neighbours switches only one pair, so at least 15 swaps are needed, and 15 are enough.

Solution

Start with the example in the problem. Going from ABCABC to CBACBA, the pairs A,BA,B and A,CA,C and B,CB,C all have to switch order: AA starts before BB and ends after it, and so on. That is 33 pairs, and the example used 33 swaps. This suggests counting pairs.

1. Count the pairs. In ABCDEFABCDEF, every pair of letters is in alphabetical order. In FEDCBAFEDCBA, every pair is in the opposite order. So every pair must switch. With 66 letters, the number of pairs is
5+4+3+2+1=155 + 4 + 3 + 2 + 1 = 15
(AA pairs with 55 letters after it, BB with 44, and so on). This is also (62)=15\binom{6}{2} = 15.
2. One swap flips only one pair. When you swap two letters that are next to each other, only those two letters change order. Every other letter stays on the same side of each of them. So each swap switches exactly one pair.
3. So at least 15 swaps are needed, because 1515 pairs have to switch and each swap handles only one.
4. 15 swaps are enough. Move AA to the end one step at a time (55 swaps): BCDEFABCDEFA. Then move BB right until it sits just before AA (44 swaps): CDEFBACDEFBA. Then CC (33 swaps): DEFCBADEFCBA. Then DD (22 swaps): EFDCBAEFDCBA. Then EE (11 swap): FEDCBAFEDCBA. Total: 5+4+3+2+1=155 + 4 + 3 + 2 + 1 = 15.

At least 1515 are needed and 1515 are enough, so the minimum is 1515.

The answer is (D) 15\boxed{\textbf{(D)}\ 15}.

Why this works

When a move can only change a count by 11, that count tells you the fewest moves you need. Here the count is "how many pairs are still in the wrong order", and each swap of neighbours changes it by exactly 11. Reversing nn letters always takes 1+2+⋯+(n−1)1 + 2 + \cdots + (n-1) swaps; the example with 33 letters and 33 swaps is the small case.

Concise solution

A shorter write-up, the way contest solutions are usually written. It may take a different route from the solution above.

Look at pairs of letters. In ABCDEFABCDEF every pair is in alphabetical order; in FEDCBAFEDCBA every pair is reversed. There are (62)=15\binom{6}{2} = 15 pairs.

A swap of two adjacent letters changes the relative order of exactly one pair (the two letters swapped) and leaves every other pair alone. So each swap fixes at most one of the 1515 pairs, and at least 1515 swaps are needed.

Fifteen swaps suffice: move AA to the right end with 55 swaps (BCDEFABCDEFA), then BB to the second-to-last spot with 44 swaps (CDEFBACDEFBA), then CC with 33, DD with 22, EE with 11: total 5+4+3+2+1=155+4+3+2+1 = 15, ending at FEDCBAFEDCBA.

The answer is (D) 15\boxed{\textbf{(D)}\ 15}.

Review in the AoPS books

Similar problems

Problem © Mathematical Association of America (MAA), American Mathematics Competitions. Reproduced for non-commercial educational use. Solution and commentary are original to this site.