Last active
November 12, 2020 15:38
-
-
Save jeb2239/17d37b626292dd41a9ec6d32956db923 to your computer and use it in GitHub Desktop.
medhi/code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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