Java Solution with explanation
\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nLet us assume a string is valid 
\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet us assume a string is valid if it contains atleast one ```a,b,c``` characters. To keep track if the current string is valid or not we use a ```size``` variable.\nwe find out a valid substring starting at index ```start``` which is initially 0. If we find a substring to be valid from ```start...i``` then all the substrings starting with ```start``` and ```ending with any index greater than or equal to i``` will be a valid substring which will be added to the result. When we find a valid substring we increment ```start``` to find the all the valid substrings starting with the ```new start index``` .\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int freq[]=new int[3];\n        int size=3;\n        int start=0;\n        int n=s.length();\n        int res=0;\n        for(int i=0;i<n;i++){\n            char a=s.charAt(i);\n            freq[a-\'a\']++;\n//when we find the first occurence of a character\n            if(freq[a-\'a\']==1){\n                size--;\n            }\n//when the substring start...i is valid  \n            while(size==0&&start<n){\n                res+=n-i;\n                freq[s.charAt(start)-\'a\']--;\n                if(freq[s.charAt(start)-\'a\']==0){\n                    size++;\n                }\n                start++;\n                \n            }\n        }\n        return res;\n    }\n}\n```
['Sliding Window', 'Java']