Find the substrings
Practice
3.3 (23 votes)
Algorithms
Medium
Problem
35% Success 5290 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Given a string S made of letters a, b and c, find the number of sub strings that do not contain all the letters a, b and c. That is the number of sub strings that do not contain at least one of the letters a or b or c.

Note that the sub string should contain atleast one letter, that is it should not be empty string.

Input
First line of the input is the number of test cases T. It is followed by T lines. Each test case is a single line which is the string S.

Output
For each test case, print a single number, the required answer.

Constraints
1 <= |S| <= 10^6

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Ad-HocAlgorithmsApprovedMediumOpen
Points:30
24 votes
Tags:
AlgorithmsApprovedData StructuresMediumOpenSorting
Points:30
7 votes
Tags:
AlgorithmsBasics of String ManipulationString Algorithms