C++ short solution O(N) time O(1) memory
\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        vector<int> idx(3,-1);\n        int res = 0;\n        for (int i = 0; i < s.length(
```\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        vector<int> idx(3,-1);\n        int res = 0;\n        for (int i = 0; i < s.length(); i++)\n        {\n            idx[s[i]-\'a\'] = i;\n            res += min(idx[0], min(idx[1], idx[2]))+1;\n        }\n        return res;\n    }\n};\n```
['C', 'C++']