Flip Prefix
You are given a **binary** string $S$ of length $N$, i.e. $S_i = 0$ or $1$. You can do the following operation as many times as you want (possibly zero): - Choose a prefix $S[1, X]$ ($1 \le X \le N$) such that there are equal number of $0$s and $1$s in this prefix, and then flip$^{\dagger}$ that prefix. For example, in the string $001101$, we can choose the prefix of length $4$ which has $2$ $
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