C - Count xxx Editorial by spheniscine
Decompose \(S\) into “runs”, where a run is a maximal substring that contains one distinct character. You can then know, for each character from a
to z
, the maximum-length run of that character in \(S\). Note that if the maximum length run for a character is \(x\), this means there are \(x\) distinct substrings being repetitions of that character, so we could simply sum these to get the answer.
posted:
last update: