text of lowercase English letters and an integer times.
Call a non-empty stretch of the string (a run of consecutive characters) **even** if both hold:
- every letter that appears in it appears exactly times times;
- any two neighbouring letters in it are at most two positions apart in the alphabet: a may stand next to c, but not next to d.
Return the number of even stretches in text. Stretches at different positions count separately even if they spell the same string.text="aabbzz", times=2 → 4
"aa", "bb", "aabb" and "zz" qualify. "bbzz" does not: b and z are too far apart in the alphabet.
text="abcabc", times=1 → 15
We need stretches where every letter appears exactly once: 6 of length 1, 5 of length 2 and 4 of length 3.
text="kkk", times=2 → 2
"kk" qualifies at positions 0–1 and at positions 1–2. The whole string does not: it has three ks.
text consists of lowercase English letters onlytext="aabbzz", times=2
4
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.