Count subsequences problem


The code is giving incorrect ouput for inputs like AAA

See you are counting subsequence of AAA so subsequence of AAA will be nothing but this only. So technically output of your code is right

A
A
A
AA
AA
AA
AAA
Instead of map use set to get outcome, take this for reference and in this code too you can see subsequence of AAA

the code is giving tle

That’s because it’s a dp problem. I just told you an optimise way of your code.
To solve this problem follow this link for dp approach
Link

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.