Beginnings and Endings
An array $A$ of length $N$ is called *good* if its first element is equal to its last element, i.e. if $A_1 = A_N$ (using $1$-indexing). You are given an array $A$ of length $N$. In one move, you can swap two **adjacent** elements of $A$, i.e. choose an index $i$ ($1 \le i \lt N$) and $\text{swap}(A_i, A_{i+1})$. Find the **minimum** number of moves needed to make the array $A$ *good*. If it'
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start