C++ solution || faster than 99.17% || O(n) time || O(1) space || Easy
\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        int n=s.size();\n        int res=0, i=0;\n        int a=-1, b=-1, c=-1;\n        wh
```\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        int n=s.size();\n        int res=0, i=0;\n        int a=-1, b=-1, c=-1;\n        while(i<n) {\n            curr=0;\n            if(s[i]==\'a\')\n                a=i;\n            else if(s[i]==\'b\')\n                b=i;\n            else\n                c=i;\n            if(a>=0 && b>=0 && c>=0) \n                res+=min(a, min(b,c))+1;\n            i++;\n        }\n     return res;\n    }\n};\n/* \nif(find helpful) {\ndo upvote(); // thanks\n}\n*/\n```
['String']