Skip to content

Instantly share code, notes, and snippets.

@jeb2239
Last active November 12, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeb2239/17d37b626292dd41a9ec6d32956db923 to your computer and use it in GitHub Desktop.
Save jeb2239/17d37b626292dd41a9ec6d32956db923 to your computer and use it in GitHub Desktop.
medhi/code.py
class Solution:
# you need startIdx for this prob
def countVowelStrings(self, n: int) -> int:
vowels = ['a','e','i','o','u']
result=[]
def cvs(curr,n,startIdx):
if n==1:
result.append(curr)
return 1
nways=0
for i in range(startIdx,5):
nways+=cvs(curr+vowels[i],n-1,i)
return nways
total=0
memoize=[[-1 for i in range(5)] for i in range(n+1)]
def cvsMemo(n,startIdx):
if memoize[n][startIdx]!=-1:
return memoize[n][startIdx]
if n==1:
memoize[n][startIdx]=1
return 1
nways=0
for i in range(startIdx,5):
nways+=cvsMemo(n-1,i)
memoize[n][startIdx]=nways
return nways
cvs=cvsMemo
for i,v in enumerate(vowels):
total+=cvs(n,i)
# print(memoize)
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment