Equal Inversions
JJ has two binary strings $A$ and $B$, both of length $N$. He can perform the following operations on $A$: $\\$ **1.** Pick any index $i$ $(1 \le i \le N)$ and flip $A_i$ (i.e. change $0$ to $1$ and $1$ to $0$) $\\$ **2.** Reverse $A$ JJ wants the number of *inversions* in $A$ to be equal to the number of *inversions* in $B$ by performing **at most** $\lceil \frac{N}{2} \rceil$ operations. Can y
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