← All problemsSign in

Square String

CodeChefRating 2002Open on judge ↗

The *sqing* value for a binary string $S$ of length $N$ is calculated as follows: - Let $X = 0$ be the initial sqing value. - For each $i$ from $1$ to $N$, let $j$ be the **largest** index such that $1 \leq j \lt i$ and $S_j \neq S_i$. If such an index $j$ exists, add $(i-j)^2$ to $X$, otherwise do nothing. For example, consider $S = \texttt{000110}$. - For $i = 1, 2, 3$, there is no $j \lt i$

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