I am able to print all subsequences of array but I cannot find a way to print number of subsequences because I cannot return a string value and also I printing the length of curStr in function itself gives wrong answer.
this is my code:
#include
#include
using namespace std;
void printSubsequences(string str, int start, int end, string curStr){
//base case
if (start == end) {
return;
}
//print current string permutation
cout<<curStr<< " ";
for (int i = start + 1; i< end; i++) {
curStr += str[i];
printSubsequences(str, i, end, curStr);
curStr = curStr.erase(curStr.size() - 1);
}
}
int main(){
string s;
cin>> s;
int len = s.size();
string cur="";
printSubsequences(s, -1, len,cur);
return 0;
}