Recursion-subsequences

All the test cases are failing. https://ide.codingblocks.com/s/292439

The approach you are using is correct, but the output format is not as per what is asked in the question. So for that, you can use the string in the question as:

void printSubsequences(string inp, string out)
{
if (inp.size() == 0)
{
cout << out << " ";
return;
}

char ch = inp[0];
inp = inp.substr(1);
printSubsequences(inp, out);
printSubsequences(inp, out + ch);

}

Can nothing be done in my code to change the order of the output?

No, since with the characters, you cannot reverse the order, thts why its better to solve this question using strings.

inp = inp.substr(1);
can you explain this line of code?

Substr is an inbuilt function…which can be used to get the remaining string …and since in the parameters, I have mentioned substr(1), it means that if u have a string as : abcd, then substr(1) will give you the remaining string as bcd,…this way recursion will keep on reducing the string…

1 Like