Loading Similar Posts
int fun(int j, string s, int n){
if(j==n) return 1;
if(s[j-1]=='a') return fun(j+1, s+'e', n);
else if(s[j-1]=='e') return fun(j+1, s+'a', n) + fun(j+1, s+'i',n);
else if(s[j-1]=='i') return fun(j+1, s+'a', n)+fun(j+1, s+'e', n)+fun(j+1, s+'o', n)+fun(j+1, s+'u', n);
else if(s[j-1]=='o') return fun(j+1, s+'i',n)+fun(j+1,s+'u',n);
else return fun(j+1, s+'a', n);
}
int countperms(int n){
int ans = 0;
vector<char> v = {'a', 'e', 'i', 'o', 'u'};
for(int i=0;i<5;i++){
ans += fun(1, to_string(v[i]), n);
}
return ans;
}
What were the constraints on all the 3 problems?
Please provide them too...
1<= n <= 2*10^5