CRX- Get Subsequences

I did not understand this program. Can you explain it clearly and give a clear idea.

@divyaKampalli17,

Let’s say the string is abcd.
Now the result of this will be a + subsequences(bcd).
Answer of bcd will be b + subsequences(cd).
Answer of cd will be c + subsequences(d).
Answer of subsequences(d) will be d + subsequences(""), this is where we hit our base case and return arraylist with “” (empty string).

Now if we see our recursion stack the calls are from bottom to up (subseq(d), subseq(cd), subseq(bcd)…)

So now, the for loop will be executed 1 time for empty string arraylist [""].

2 times for arraylist ["",d]. 4 times for arraylist ["",d,c,cd]. 8 times for ["",d,c,cd,b,bd,bc,bcd].

And then finally 16 times for ‘a’.

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.