← All problemsSign in

Sorting the Binary String

CodeChefRating 2690Open on judge ↗

A binary string $A$ is called *good* if it can be sorted (in non-decreasing order) using the following operation: - Select an $i$ $(1 \le i \le |A| - 1)$ and swap $A_i$ with $A_{i + 1}$. This operation can be performed on any $i$ **at most** once. For example, $A = 10110$ is *good* because we can perform the following operations: $10110 \xrightarrow{i = 1} 01110 \xrightarrow{i = 4} 01101 \xrigh

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