← All problemsSign in

Sum of Modes

CodeChefRating 1734Open on judge ↗

For a **binary** string $T$, let $f(T) = $ the number of modes$^\dagger$ of string $T$. For example, $f(101) = 1$, as it has a unique mode $1$ while $f(01) = 2$, as it has $2$ modes, both $0$ and $1$. Given a **binary** string $S$ of length $N$, compute the value of $\displaystyle{\sum_{L = 1}^{N} \sum_{R = L}^{N} f(S[L,R])}$, where $S[L,R]$ denotes the substring $S_LS_{L+1}\ldots S_R$. $^\dag

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