-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
27 lines (23 loc) · 1.19 KB
/
solution.py
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
# {a, e, i, o, u, A, E, I, O, U}
# Natural Language Understanding is the subdomain of Natural Language Processing where people used
# to design AI based applications have ability to understand the human languages.
# HashInclude Speech Processing team has a project named Virtual Assistant.
# For this project they appointed you as a data engineer
# (who has good knowledge of creating clean datasets by writing efficient code).
# As a data engineer your first task is to make vowel recognition dataset.
# In this task you have to find the presence of vowels in all possible substrings of the given string.
# For each given string you have to return the total number of vowels.
# Example
# Given a string "baceb" you can split it into
# substrings: b, ba, bac, bace, baceb, a, ac, ace, aceb, c, ce, ceb, e, eb, b.
# The number of vowels in each of these substrings is 0, 1, 1, 2, 2, 1, 1, 2, 2, 0, 1, 1, 1, 1, 0;
# if you sum up these number, you get 16 - the expected output.
def vowel_recognition(s):
vowels = 'aeiouAEIOU'
r = 0
len_s = len(s)
for i in range(0, len_s):
if s[i] in vowels:
r += (i + 1) * (len_s - i)
print(f'{i + 1}, {len_s - i}, {r}')
return r