Question: Atlassian OA | IIT Patna | SWE Internship | 2023
0
Entering edit mode

Entering edit mode
0

What were the constraints on all the 3 problems?
Please provide them too...

ADD REPLYlink 15 months ago
pogo_player
• 10
Entering edit mode
0

1<= n <= 2*10^5

ADD REPLYlink 15 months ago
Kalpit1810
• 0
0
Entering edit mode

// recursive solution of question 3;

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;

}

ADD COMMENTlink 15 months ago Aman Shankar Singh • 50

Login before adding your answer.

Similar Posts
Loading Similar Posts