Simple easy solution with comment ✅✅
\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
\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 {\npublic:\n    int numberOfSubstrings(string s) {\n        // the calculation of count can be given by (1+ end-j), which is calculated as we count all substrings from the jth point to the end of substring having the same i.(this hack will reduce TC). eg: in given example 1 of problem, if "abc" is the window, "abc", "abca", "abcab", "abcabc" is given by the above count formula.(all left chars after geting abc in string)\n        int i = 0, j = 0, n = s.length(), end = s.length()-1, ans = 0;\n        unordered_map<char,int> m;\n        while(j<n){\n            m[s[j]]++;\n            if(m.size() < 3){\n                j++;\n            }\n            else{\n                // use while loop for cases like "aaacb" -> O/P = 3\n                while(m.size()==3){\n                    ans = ans + (end - j + 1);\n                    m[s[i]]--;\n                    if(m[s[i]] == 0){\n                        m.erase(s[i]);\n                    }\n                    i++;\n                }\n                j++;\n            }\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'Sliding Window', 'C++']