← All problemsSign in

Arbitrary Shuffling

CodeChefRating 2487Open on judge ↗

You are given a permutation $P$ of the integers $[1, N]$. You can do either of the following operations as many times as you want: - Choose an index $X$ ($1 \le X \le N$) such that $P_X = X$, and **shuffle** the subarray $P[1, X]$. - Choose an index $X$ ($1 \le X \le N$) such that $P_X = X$ and **shuffle** the subarray $P[X, N]$. Here the subarray $P[L, R]$ represents the array $[P_L, P_{L + 1}

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