Simple Java Solution ✅
Approach\n- I used a nested loop to examine each substring. \n- For each starting point, I tracked character frequencies and checked if any character\'s frequen
# Approach\n- I used a nested loop to examine each substring. \n- For each starting point, I tracked character frequencies and checked if any character\'s frequency reached `k`. \n- If it did, I counted all remaining substrings from that point onward.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n- Space complexity: $$O(1)$$ (fixed size array for character frequency)\n\n# Code\n```java\nclass Solution {\n    public int numberOfSubstrings(String s, int k) {\n        int n = s.length();\n        int count = 0;\n\n        for (int left = 0; left < n; left++) {\n            int[] freq = new int[26];\n            int maxFreq = 0;\n\n            for (int right = left; right < n; right++) {\n                freq[s.charAt(right) - \'a\']++;\n                maxFreq = Math.max(maxFreq, freq[s.charAt(right) - \'a\']);\n\n                if (maxFreq >= k) {\n                    count += n - right;\n                    break;\n                }\n            }\n        }\n        return count;\n    }\n}\n```\n\n## Updated code\n\n```\nclass Solution {\n    public int numberOfSubstrings(String s, int k) {\n        int n = s.length();\n        int count = 0;\n\n        for (int left = 0; left < n; left++) {\n            int[] freq = new int[26];\n\n            for (int right = left; right < n; right++) {\n                freq[s.charAt(right) - \'a\']++;\n\n                if (freq[s.charAt(right) - \'a\'] >= k) {\n                    count += n - right;\n                    break;\n                }\n            }\n        }\n        return count;\n    }\n}\n```\n\n# Upvote if you found this helpful! \uD83D\uDE0A
['Java']