Striver's solution | 2 pointers | Sliding Window | Beginner Friendly | Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(3)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numberOfSubstrings(String s) {\n        int[] freq = new int[3];\n        Arrays.fill(freq, -1);\n\n        int count = 0;\n\n        for(int i=0; i<s.length(); i++){\n            freq[s.charAt(i)-\'a\'] = i;\n\n            if(freq[0]!=-1 && freq[1]!=-1 && freq[2]!=-1)  \n            {\n                count+= 1 + Math.min(Math.min(freq[0], freq[1]), freq[2]);\n            }\n        }\n\n        return count;\n    }\n}\n```
['Array', 'Two Pointers', 'Sliding Window', 'Java']