-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm2947.java
More file actions
29 lines (28 loc) · 861 Bytes
/
prblm2947.java
File metadata and controls
29 lines (28 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class prblm2947 {
public static void main(String[] args) {
String s = "baeyh";
int k = 2;
System.out.println(beautifulSubstrings(s, k));
}
public static int beautifulSubstrings(String s, int k) {
Set<Character> vowels = Set.of('a', 'e', 'i', 'o', 'u');
int count = 0;
for(int i=0; i<s.length(); i++){
int vowelsCount = 0;
int consonant = 0;
for(int j=i; j<s.length(); j++){
if(vowels.contains(s.charAt(j))){
vowelsCount++;
}
else{
consonant++;
}
if (vowelsCount == consonant && ((vowelsCount*consonant) % k == 0)) {
count++;
}
}
}
return count;
}
}