Skip to content

Instantly share code, notes, and snippets.

@accakks
Created June 12, 2020 19:36
Show Gist options
  • Save accakks/a485bbb51a6ce44a385082e9510046f0 to your computer and use it in GitHub Desktop.
Save accakks/a485bbb51a6ce44a385082e9510046f0 to your computer and use it in GitHub Desktop.
You are given a string S, you have to find all the ‘amazing’ substrings of S.
'''
You are given a string S, you have to find all the ‘amazing’ substrings of S.
‘Amazing’ substring is one that starts with a vowel (a,e,i,o,u,A,E,I,O,U)
Example:
Input: ABEC
Output: 6
Explanation: Amazing substrings of given string are :
1. A
2. AB
3. ABE
4. ABEC
5. E
6. EC
here number of substrings are 6
'''
def no_of_substrings(s):
"""returns number of amazing substrings of a given string
Assumption made: No repeated substrings to count"""
vowels = ('a','e','i','o','u','A','I','E','O','U')
num = 0
substrings = []
for i in range(len(s)-1,-1,-1):
if s[i] in vowels:
for k in range(0,len(s[i:])):
substrings.append(s[i:i+k+1])
#print(set(substrings))
num = len(set(substrings))
return num
s = input('Enter input string\n')
print(no_of_substrings(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment