[Python] Simple O(n) Solution with Explanation
Idea\n- Denote the length of s as n\n- For each index slow. We find the earliest index fast such that there is at last 1 occurrence for all \'a\', \'b\', \'c\'.
**Idea**\n- Denote the length of `s` as `n`\n- For each index `slow`. We find the earliest index `fast` such that there is at last 1 occurrence for all `\'a\', \'b\', \'c\'`.\n- Then there are `n - fast` different subarray starting from `slow`.\n\n**Complexity**\nTime: O(n)\nSpace: O(1)\n\n**Python 3, O(n)**\n```\nclass Solution:\n    def numberOfSubstrings(self, s: str) -> int:\n        slow, fast, n = 0, -1, len(s)\n        d = {\'a\':0, \'b\':0, \'c\':0}\n        res = 0\n        \n        while slow < n or fast < n:\n            if min(d.values()) >= 1:\n                d[s[slow]] -= 1\n                slow += 1\n            while min(d.values()) < 1:\n                if fast < n-1:\n                    fast += 1\n                    d[s[fast]] += 1\n                else:\n                    return res\n            res += n - fast\n```\n
['Python3']