Hii…
I was giving the leetcode challenge… which has just finished.
This is the 2nd question…
I was not able to come with proper solution… Some logic realted to recursion came to my mind…
Please see this question.
Thanks
Not able to solve
Yes a simple solution to this is by recursion:
class Solution {
int count = 0;
void helper(int sIndex, int n)
{
if(n ==0)
{
count++;
return;
}
for(int i =sIndex; i<5; i++)
{
helper(i,n-1);
}
}
public:
int countVowelStrings(int n) {
helper(0,n);
return count;
}
};
If you work with some test cases, you may observe that there is a pattern being followed. I would suggest you to go through this O(n) approach .