Count how many substrings contain at least one of each of the characters 'a', 'b', and 'c'.
Given a string s consisting only of the characters 'a', 'b', and 'c', count the number of substrings that contain all three characters at least once.
A substring is a contiguous block of characters within the string.
Your task is to return the total number of valid substrings.
'a', one 'b', and one 'c'.ss contains only the letters 'a', 'b', and 'c's that contain all three characters1 <= |s| <= $10^{5}$s[i] ∈ {'a', 'b', 'c'}Example 1
Input
s = "abcabc"
Output
10
Explanation
Valid substrings include "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc", and another "abc" starting later.
Example 2
Input
s = "aaacb"
Output
3
Explanation
The valid substrings are "aaacb", "aacb", and "acb".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.