Skip to content

Commit 06d82f3

Browse files
committed
new question added
1 parent 17a13be commit 06d82f3

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Question :
3+
Given a string consisting of English alphabets, the task is to count the number of adjacent pairs of vowels.
4+
For example :
5+
Input: str = “abaebio”
6+
Output: 2
7+
(a, e) and (i, o) are the only valid pairs.
8+
Source:A very Common Interview Question.
9+
10+
Time Complexity : The goal is to complete this question in O(n).
11+
'''
12+
13+
#function to check whether a character is vowel or not
14+
def is_vowel(character):
15+
if character.lower() in ['a', 'e', 'i', 'o', 'u']:
16+
return True
17+
else:
18+
return False
19+
20+
21+
#function to find the number of adjacent vowel pairs.
22+
def adjacent_pairs(string):
23+
string=string.lower()
24+
n=len(string)
25+
count = 0
26+
for i in range(0,n):
27+
if ((is_vowel(string[i]) and is_vowel(string[i + 1]))):
28+
count += 1
29+
return count
30+
31+
#driver code
32+
string=input("enter string")
33+
print (adjacent_pairs(string),"is the number of adjacent pairs of vowels")
34+

0 commit comments

Comments
 (0)