← All problemsSign in

Swap Sort

CodeChefRating 2980Open on judge ↗

You are given a permutation of $n$ $a_1,a_2,...a_n$. You will also be given another integer $x$ between $1$ and $n$. In one move, you can swap the element $x$ with an element at an odd number of places to the left or right of it. For example, if $x$ is at position $i$, then you can swap it with $a_{i+1},a_{i+3},...$ and $a_{i-1},a_{i-3},...$ Your task is to sort the array in at most $10n$ mov

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start