Given a string s containing only characters a, b, c, return the number of substrings containing at least one occurrence of all three characters.
Sliding window: for each right, maintain the last seen position of a, b, c. When all three are seen, all substrings ending at right and starting from 0 to min(last_a, last_b, last_c) are valid.
- Track last[] = last index seen for each of a, b, c.
- For each right, update last[s[right]-a] = right.
- If all three have been seen: count += min(last[a], last[b], last[c]) + 1.
- This is because we can choose any left from 0 to min(last positions).
- Time Complexity: O(N)
- Space Complexity: O(1)