This content originally appeared on DEV Community and was authored by Prashant Mishra
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
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
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/
" » 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/
HARVARDPrashant 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/>
VANCOUVERPrashant 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.