Count Substrings With K-Frequency Characters I

Problem

class Solution {
public int numberOfSubstrings(String s, int k) {
int left =0, right = 0;
int hash[] = new int[26];
int count = 0;
while(right<s.length()){
char c= s.charAt(right);


This content originally appeared on DEV Community and was authored by Prashant Mishra

Problem

class Solution {
    public int numberOfSubstrings(String s, int k) {
        int left  =0, right = 0;
        int hash[] = new int[26];
        int count = 0;
        while(right<s.length()){
            char c= s.charAt(right);
            hash[c-'a']++;
            while(hash[c-'a']>=k){
                count = count+1 + s.length()-1-right;
                hash[s.charAt(left)-'a']--;
                left++;
            }
            right++;
        }
        return count;
    }
}


This content originally appeared on DEV Community and was authored by Prashant Mishra


Print Share Comment Cite Upload Translate Updates
APA

Prashant Mishra | Sciencx (2024-10-20T04:16:19+00:00) Count Substrings With K-Frequency Characters I. Retrieved from https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/

MLA
" » Count Substrings With K-Frequency Characters I." Prashant Mishra | Sciencx - Sunday October 20, 2024, https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/
HARVARD
Prashant Mishra | Sciencx Sunday October 20, 2024 » Count Substrings With K-Frequency Characters I., viewed ,<https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/>
VANCOUVER
Prashant Mishra | Sciencx - » Count Substrings With K-Frequency Characters I. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/
CHICAGO
" » Count Substrings With K-Frequency Characters I." Prashant Mishra | Sciencx - Accessed . https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/
IEEE
" » Count Substrings With K-Frequency Characters I." Prashant Mishra | Sciencx [Online]. Available: https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/. [Accessed: ]
rf:citation
» Count Substrings With K-Frequency Characters I | Prashant Mishra | Sciencx | https://www.scien.cx/2024/10/20/count-substrings-with-k-frequency-characters-i/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.