[C++] Easy Sliding Window Approach O(n) O(1)
class Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        int n = s.size();\n        \n        int a = 0, b = 0, c = 0 ,j = 0 , ans = 0;\n     
class Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        int n = s.size();\n        \n        int a = 0, b = 0, c = 0 ,j = 0 , ans = 0;\n        for(int i = 0; i < n; i++)\n        {\n            if(s[i] == \'a\')\n                a++;\n            if(s[i] == \'b\')\n                b++;\n            if(s[i] == \'c\')\n                c++;\n            \n            if(a > 0 && b > 0 && c > 0)\n            {\n                while(a > 0 && b > 0 && c > 0)\n                {\n                    ans+= n - i;\n                    if(s[j] == \'a\')\n                        a--;\n                    if(s[j] == \'b\')\n                        b--;\n                    if(s[j] == \'c\')\n                        c--;\n                    j++;\n                }\n            }\n        }\n        return ans;\n    }\n};
['Sliding Window']