-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm2559.java
More file actions
43 lines (41 loc) · 1.39 KB
/
prblm2559.java
File metadata and controls
43 lines (41 loc) · 1.39 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Set;
public class prblm2559 {
public static void main(String[] args) {
String[] words = {"aba","bcb","ece","aa","e"};
int[][] queries = {{0,2}, {1,4}, {1,1}};
int[] ans = vowelStrings(words, queries);
for (int i : ans) {
System.out.println(i);
}
}
// static int[] vowelStrings(String[] words, int[][] queries) {
// for (int[] query : queries) {
// int left = query[0];
// int right = query[1];
// }
// }
// static int calculateNoOfVowels(int[] words, int left, int right){
// for (int i = left; i < right; i++) {
// if () {
// }
// }
// }
public static int[] vowelStrings(String[] words, int[][] queries) {
Set<Character> vowels = Set.of('a', 'e', 'i', 'o', 'u');
int n = words.length;
int[] s = new int[n + 1];
for (int i = 0; i < n; ++i){
char a = words[i].charAt(0);
char b = words[i].charAt(words[i].length() - 1);
s[i + 1] = s[i] + (vowels.contains(a) && vowels.contains(b) ? 1 : 0);
}
int m = queries.length;
int[] ans = new int[m];
for (int i = 0; i < m; ++i){
int left = queries[i][0];
int right = queries[i][1];
ans[i] = s[right + 1] - s[left];
}
return ans;
}
}