Skip to content

Commit f1496a7

Browse files
Add files via upload
1 parent f5241bb commit f1496a7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Strings/AmazingSubarrays.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
You are given a string S, and you have to find all the amazing substrings of S.
3+
4+
Amazing Substring is one that starts with a vowel (a, e, i, o, u, A, E, I, O, U).
5+
6+
Input
7+
8+
Only argument given is string S.
9+
Output
10+
11+
Return a single integer X mod 10003, here X is number of Amazing Substrings in given string.
12+
Constraints
13+
14+
1 <= length(S) <= 1e6
15+
S can have special characters
16+
Example
17+
18+
Input
19+
ABEC
20+
21+
Output
22+
6
23+
24+
Explanation
25+
Amazing substrings of given string are :
26+
1. A
27+
2. AB
28+
3. ABE
29+
4. ABEC
30+
5. E
31+
6. EC
32+
here number of substrings are 6 and 6 % 10003 = 6.
33+
34+
LINK: https://www.interviewbit.com/problems/amazing-subarrays/
35+
*/
36+
37+
#define MOD 10003
38+
39+
bool check(char c)
40+
{
41+
c = tolower(c);
42+
if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
43+
return true;
44+
return false;
45+
}
46+
47+
int Solution::solve(string A)
48+
{
49+
int n = A.length();
50+
int ans = 0;
51+
52+
for(int i=0;i<n;i++)
53+
{
54+
if(check(A[i]))
55+
{
56+
ans = (ans + (n-i))%MOD;
57+
}
58+
}
59+
60+
return ans;
61+
}

0 commit comments

Comments
 (0)