DEV Community

Prashant Mishra
Prashant Mishra

Posted on

count-of-substrings-containing-every-vowel-and-k-consonants-i

Problem

class Solution {
    public int countOfSubstrings(String word, int k) {
        int count = 0;
        for(int i =0;i<word.length();i++){
            HashMap<Character,Integer> map = new HashMap<>();
            int consonent = 0;
            for(int j = i;j<word.length();j++){
                char c = word.charAt(j);
                if(c =='a' || c =='e' || c=='i' || c =='o' || c =='u'){
                    map.put(c,map.getOrDefault(c,0)+1);
                }
                else consonent++;
                if(map.size() ==5 && consonent ==k)count++;
            }


        }
        return count;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)