C++ solution
\nstatic bool fast = []()\n{\n    std::cin.tie(0)->sync_with_stdio(false);\n    return true;\n}();\n\nclass Solution\n{\npublic:\n    int numberOfSubstrings(con
```\nstatic bool fast = []()\n{\n    std::cin.tie(0)->sync_with_stdio(false);\n    return true;\n}();\n\nclass Solution\n{\npublic:\n    int numberOfSubstrings(const string& s, int k)\n    {\n        int res = 0;\n\n        int left = 0;\n        int right = 0;\n        std::unordered_map<char, int> freq;\n        int count_at_least = 0;\n        while (right < s.length())\n        {\n            freq[s[right]]++;\n\n            if (freq[s[right]] >= k)\n            {\n                count_at_least++;\n            }\n\n            while (left <= right && count_at_least > 0)\n            {\n                res += s.length() - right;\n\n                int f_before = freq[s[left]];\n                freq[s[left]]--;\n                if (f_before >= k && freq[s[left]] < k)\n                {\n                    count_at_least--;\n                }\n                left++;\n            }\n\n            right++;\n        }\n\n        return res;\n    }\n};\n```
['C++']