Wrong Answer- Suppose we have to generate the number as well

#include

using namespace std;

int distinct_ele(char *out, int i, int n){

//if we have reached the last element
if(i==n){
	return 1;
}

out[i]='a';

int distinct_a=distinct_ele(out,i+1,n);

int distinct_b=0; //let's assume can't put

if(i!=0 && out[i-1]!='b'){

	out[i]='b';

	distinct_b=distinct_ele(out,i+1,n);

}

return distinct_b+distinct_a;

}

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	char out[100];

	cin>>n;

	cout<<distinct_ele(out,0,n);



return 0;

}

hello @rachitbansal2500

call ur function twice.
one by putting ‘a’ at out[0]
and one by putting ‘b’ at out[0] // <- this case is never included in ur current code

1 Like

Got it. Thank you so much!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.