We’re preparing your current view and syncing the latest data.
Count Substrings Containing All Three Characters
gfgGiven a string s consisting only of characters 'a', 'b' and 'c', return the number of substrings containing at least one occurrence of all these characters 'a', 'b' and 'c'.
A single string s of length n containing only characters 'a', 'b', and 'c'.
An integer representing the number of substrings containing at least one 'a', one 'b', and one 'c'.
1 <= s.length <= 5 * 10^4 s consists only of 'a', 'b', or 'c'.
Example 1
Input
"abcabc"
Output
10
Explanation
There are 10 substrings containing all three characters 'a', 'b', and 'c'.
Example 2
Input
"aaacb"
Output
3
Explanation
The substrings are 'aaacb', 'aacb', and 'acb'.