Ctrl K

Windows Holding a, b and c

Medium
The string text is made only of the letters a, b and c. Count its contiguous pieces (substrings) in which each of the three letters appears at least once. Pieces with the same content at different positions are counted separately.
Example 1
text='abca' → 3

"abc", "abca" and "bca" qualify. Every other piece misses at least one letter.

Example 2
text='ccab' → 2

Any valid piece must include the final "ab" and at least one "c" before it: "cab" and "ccab".

Example 3
text='aabb' → 0

There is no "c" at all, so the answer is 0.

Constraints
  • 3 ≤ len(text) ≤ 5 · 10⁴
  • text contains only a, b and c
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Repeat-Free Stretch MediumTwo-Letter Stretch MediumRecurring Gene Windows MediumWindow with Few Kinds of Letters MediumEvery Letter at Least k Times Medium
loading Python…
Input
text='abca'
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 133 tests on the server, hidden ones included.