Easily Understandable Sliding Window | c++ | using unordered_map
Intuition\nWe will use sliding window method to solve this problem.\n\nwe will use unordered_map to keep track when all three character is present in substring\
# Intuition\nWe will use sliding window method to solve this problem.\n\nwe will use unordered_map to keep track when all three character is present in substring\n\nwhen all three character is present then there are n-j possibe substring\n\n```\nHappy coding and do upvote if it helped :)\n```\n# Complexity\n- Time complexity:\n$$O(N)$$\n\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfSubstrings(string s) {\n        unordered_map<char,int> st;\n        int n=s.size();\n        int i=0,j=0;\n        int ans=0;\n\n        while(j<n){\n            st[s[j]]+=1;\n\n            // Condition of window hit\n            if(st[\'a\']>0 && st[\'b\']>0 && st[\'c\']>0){  \n                // until our window is not breaking we need to add all possible substring in out answer\n                while(st[\'a\']>0 && st[\'b\']>0 && st[\'c\']>0){\n                    ans+= (n-j);\n                    if(s[i]==\'a\') st[\'a\']-=1;\n                    else if(s[i]==\'b\') st[\'b\']-=1;\n                    else st[\'c\']-=1;\n                    i+=1;\n                }\n            }\n            j+=1;\n        }\n        return ans;\n    }\n};\n```
['Sliding Window', 'C++']