java | sliding window | HashMap
\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int ans=0;\n        HashMap<Character,Integer>hm=new HashMap<>();\n        int i=0;\n
```\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int ans=0;\n        HashMap<Character,Integer>hm=new HashMap<>();\n        int i=0;\n        for(int j=0;j<s.length();j++){\n            hm.put(s.charAt(j),hm.getOrDefault(s.charAt(j),0)+1);\n            while(hm.size()==3){\n                ans+=(s.length()-j);\n                if(hm.get(s.charAt(i))>1){\n                    hm.put(s.charAt(i),hm.get(s.charAt(i))-1);\n                }\n                else{\n                    hm.remove(s.charAt(i));\n                }\n                i++;\n            }\n        }\n        return ans;\n    }\n}\n```
[]