File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+
4
+ // to check if the char is vowel or not
5
+ bool checkvowel(char ch){
6
+ if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') return true;
7
+ return false;
8
+ }
9
+
10
+ vector<int> vowelStrings(vector<string>& words, vector<vector<int>>& queries) {
11
+
12
+ vector<int>mpp(words.size()); // to store the prefix count of vowels
13
+ vector<int>ans; // to store the result
14
+ int cnt=0; // to count string following the constraint
15
+
16
+ // filling prefix vec
17
+ for(int i=0;i<words.size();i++){
18
+ if(words.at(i).size()==1&&checkvowel(words.at(i)[0])) cnt++;
19
+ else if(checkvowel(words.at(i)[0])&&checkvowel(words.at(i)[words.at(i).size()-1]))cnt++;
20
+ mpp[i]=cnt;
21
+ }
22
+
23
+ // using prefix vec to fill the result vec
24
+ for(int j=0;j<queries.size();j++){
25
+ if(queries.at(j)[0]==0)ans.push_back(mpp[queries.at(j)[1]]);
26
+ else ans.push_back(mpp[queries.at(j)[1]]-mpp[queries.at(j)[0]-1]);
27
+ }
28
+ return ans;
29
+ }
30
+ };
You can’t perform that action at this time.
0 commit comments