Arrange the array
CodeChefOpen on judge ↗
You are given an array $A$ of size $N$. Let $B$ denote the array obtained by sorting $A$ in increasing order, and $C$ denote the array obtained by sorting $A$ in decreasing order. Consider all permutations $D$, of the array $A$, such that $D$ is **not equal** to $B$ and $D$ is **not equal** to $C$. We define the score of such $D$ as: $\texttt{min}(|D_i - D_{(i-1)}|)$ , for $(1\lt i\le N)$.
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