✨Easy Approach CPP ||💪Beats 100.00% ||✅✅☑️☑️
Approach:\n# Initialize Variables:\n\n- Use an integer totalCount to keep track of the total valid substrings.\n- Use a vector of size 26 (for each lowercase le
# Approach:\n# Initialize Variables:\n\n- Use an integer totalCount to keep track of the total valid substrings.\n- Use a vector<int> of size 26 (for each lowercase letter) to store the frequency of characters in the current sliding window.\n- Set up two pointers, left and right, to represent the current window of characters in the string.\n# Expand the Window:\n\n- Iterate over the string with the right pointer.\n- For each character, increment its frequency in the freq array.\n# Check Frequency Condition:\n\n- Use a loop to check if any character in the freq array has a frequency of at least k.\n- If the condition is met, count all substrings starting from left to right, which is calculated as (n - right) where n is the length of the string.\n# Contract the Window:\n\n- After counting valid substrings, move the left pointer to contract the window and decrement the frequency of the character at the left pointer.\n# Return the Result:\n\n- After processing the entire string, return totalCount as the result.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int numberOfSubstrings(string s, int k) {\n        int n = s.length();\n        int totalCount = 0;\n        vector<int> freq(26, 0); // Frequency of each character in the current window\n        int left = 0; // Left pointer of the sliding window\n        \n        // Iterate over each character with right pointer expanding the window\n        for (int right = 0; right < n; right++) {\n            // Update frequency of the current character\n            freq[s[right] - \'a\']++;\n            \n            // Check if there is any character with frequency >= k\n            while (any_of(freq.begin(), freq.end(), [k](int count) { return count >= k; })) {\n                // If condition met, count all substrings from left to the current right\n                totalCount += (n - right);\n                // Contract the window from the left side by moving left pointer\n                freq[s[left] - \'a\']--;\n                left++;\n            }\n        }\n        \n        return totalCount;\n    }\n};\n\n```
['C++']