388. Number of Substrings Containing All Three Characters

Given a string s , consisting only of characters 'a' , 'b' , 'c'.Find the number of substrings that contain at least one occurrence of all these characters 'a' , 'b' , 'c'.

Example 1:

Input : s = "abcba"

Output : 5

Explanation : The substrings containing at least one occurrence of the characters 'a' , 'b' , 'c' are "abc" , "abcb" , "abcba" , "bcba" , "cba".

Example 2:

Input : s = "ccabcc"

Output : 8

Explanation : The substrings containing at least one occurrence of the characters 'a' , 'b' , 'c' are "ccab" , "ccabc" , "ccabcc" , "cab" , "cabc" , "cabcc" , "abc" , "abcc".

Now Your Turn!

Pick the correct output for the given input

Input : s = "abccba"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 5*104
  • s consist only of characters 'a' , 'b' , 'c'.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int numberOfSubstrings(string s) {
//your code goes here
}
};
Test Case

Input:

S