Sir I am getting correct results during compilation but getting wrong answers during submissions.
Getting wrong answer
#include
using namespace std;
int count=0;
void subsequence(char *inp,char *out,int i,int j)
{
if(inp[i]==’\0’)
{
out[j]=’\0’;
count++;
cout<<out<<" ";
return;
}
out[j]=inp[i];
subsequence(inp,out,i+1,j+1);
subsequence(inp,out,i+1,j);
}
int main() {
char inp[100];
cin>>inp;
char out[100];
subsequence(inp,out,0,0);
cout<<endl;
cout<<count;
return 0;
}
@Hk199977
The order of your output is wrong.
For the test case abcd, the correct order should be:
d c cd b bd bc bcd a ad ac acd ab abd abc abcd
16
while your code gives:
abcd abc abd ab acd ac ad a bcd bc bd b cd c d
16
So, make this right.
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.