[Java] Sliding window O(N) solution
\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int[] track = new int[3]; //also we can use 3 variables for counting (a, b, c)\n     
```\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int[] track = new int[3]; //also we can use 3 variables for counting (a, b, c)\n        int res = 0;\n        int left = 0;\n        for (int i = 0; i < s.length(); i++) {\n            track[s.charAt(i) - \'a\']++;\n\n            while (track[0] > 0 && track[1] > 0 && track[2] > 0) {\n                res += s.length() - i;\n                track[s.charAt(left++) - \'a\']--;\n            }\n        }\n        return res;\n    }\n}\n```
['Sliding Window', 'Java']