Counting Substrings With Vowels And Consonants In A String
Count substrings with sum/k or count=k in O(n) time using a sliding window approach with a map to track vowel counts.
Problem
Pattern: number of subarray/substring with condition like sum ==k or count = k
TC: O(n)
class Solution {
public long countOfSubstrings(String word, int k) {
return Math.abs(find(word,k) - find(word,k+1));
}
public long find(String w, int k){
if(k<0) return 0;
Map<Character,Integer> map = new HashMap<>();
int left =0;
int right =0;
int con = 0;
long count=0;
while(right < w.length()){
char cr = w.charAt(right);
if(isv(cr)){
map.put(cr,map.getOrDefault(cr,0)+1);...