How to get required output

the output should be
d c cd b bd bc bcd a ad ac acd ab abd abc abcd
16
but my output is
abcd abc abd ab acd ac ad a bcd bc bd b cd c d
16
what to edit in code for this?
Here is my code-

just first exclude and then include character

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.