output is coming correct but it is failing in all test cases
Test case is not coming correct
#include using namespace std; void pix(char str[],char out[],int spos,int opos,int &cnt) { if(str[spos]==’\0’) { out[opos]=’\0’; cnt=cnt+1; cout<<out<<" "; return; } out[opos]=str[spos]; pix(str,out,spos+1,opos+1,cnt); pix(str,out,spos+1,opos,cnt); } int main() { char str[1000],out[1000]; int cnt=0; cin.getline(str,1000); pix(str,out,0,0,cnt); cout<<endl; cout<<cnt; }
Hi @yashsingh9289
Test cases are not passing because you are printing the output in reverse order. So to correct it, instead of printing out string you just push it in a stack and then in the main function just print all the elements in the stack.
Here is your corrected code :
If your doubt is clear then mark it as resolved.