Skip to content

Commit

Permalink
Create 2559. Count Vowel Strings in Ranges.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh-addagatla authored Jan 2, 2025
1 parent 6040b31 commit c348513
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2559. Count Vowel Strings in Ranges.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int[] vowelStrings(String[] words, int[][] queries) {
int n=words.length;
int[] Prefix = new int[n+1];
Set<Character> vowels = new HashSet<>(Arrays.asList('a','e','i','o','u'));
for(int i=0 ; i<n ; i++){
Prefix[i+1]=Prefix[i];
if(vowels.contains(words[i].charAt(0)) && vowels.contains(words[i].charAt(words[i].length()-1))){
Prefix[i+1]++;
}
}
int[] ans = new int[queries.length];
for(int i=0;i<queries.length;i++){
ans[i]=Prefix[queries[i][1]+1] - Prefix[queries[i][0]];
}
return ans;
}
}

0 comments on commit c348513

Please sign in to comment.