Best O(N) Solution
Approach 1\nBrute-Force\n\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n    int numberOfSubstri
# Approach 1\nBrute-Force\n\n# Complexity\n- Time complexity:\n$$O(n^2)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        int n = s.length();\n        int count = 0;\n        for (int i = 0; i < n; i++) {\n            unordered_map <char, int> mp;\n            for (int j = i; j < n; j++) {\n                mp[s[j]]++;\n                if (mp[\'a\'] > 0 && mp[\'b\'] > 0 && mp[\'c\'] > 0)\n                    count++;            \n            }\n        }\n        return count;\n    }\n};\n```\n\n# Approach 2\nSliding Window\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        int n = s.length();\n        unordered_map <char, int> mp;\n        int start = 0, end = 0;\n        int count = 0;\n        while (end < n) { \n            mp[s[end]]++;        \n            while (mp[\'a\'] > 0 && mp[\'b\'] > 0 && mp[\'c\'] > 0) {\n                count += n - end; \n                mp[s[start]]--;\n                start++; \n            }  \n            end++; \n        }    \n        return count;\n    }\n};\n```
['C++']