← All problemsSign in

Sort Lexicographically

CodeChefRating 2940Open on judge ↗

For an array $B$ of $M$ **distinct** positive integers, we define a function $F(B)$ as follows: 1. Initialise an empty array $C$ and mark all indices of $B$ (from $1$ to $M$) as unmarked. 2. Repeat the following step exactly $M$ times: - Choose an unmarked index $i$ that is adjacent to a marked index (or any index in the first iteration). - Append $B_i$ to the end of $C$. - Mark index $i$

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