Balance Substrings
For a binary string $S$, and an integer $K$, we define $f(S, K)$ as the minimum sum of costs of choosing $K$ non-intersecting substrings from $S$. The cost of a substring is it's balance, i.e. $|c_0 - c_1|$ where $c_0$ represents the number of $0$s and $c_1$ the number of $1$s. Note that it is not necessary that every element be part of some chosen substring. For example, $f(1011, 2)$ is $1$ bec
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