Python3 Solution | Sliding Window Technique | O(N) Time Complexity and O(1) Space Complexity
Approach:\nSliding Window :\n1. First set a seen dictionary which has keys a,b and c with initial count zero for each of them.\n2. sliding the window as long as
Approach:\nSliding Window :\n1. First set a seen dictionary which has keys a,b and c with initial count zero for each of them.\n2. sliding the window as long as all of them exist at least once.\n3. If all of them exist at least once then the substring so far and next n- j substrings will be valid substrings that fit for our problem solution. so our count will be increment by n-j + 1 where n is the length of the string s and j is the faster pointer.\n4. Then return the count of the substring that is valid in the given constraints.\n# PLZ UPVOTE\n```\ndef numberOfSubstrings(self, s: str) -> int:  \n\tseen = {"a":0,"b":0,"c":0}\n\ti = j = 0\n\tcount = 0\n\tn = len(s)\n\twhile i + 3 <= n:\n\t\tif seen["a"] >=1 and seen["b"] >=1 and seen["c"] >=1:\n\t\t\tseen[s[i]] -=1\n\t\t\ti +=1\n\t\t\tcount += n-j+1\n\t\telse:\n\t\t\tif j <= n-1:\n\t\t\t\tseen[s[j]] +=1\n\t\t\t\tj +=1\n\t\t\telse:\n\t\t\t\tbreak\n\treturn count\n
['Sliding Window', 'Python', 'Python3']