Recursion - All Subsequences

Please check my code. It is giving the correct output for the given input in question.
But a wrong answer as soon as I submit it.
Also suggest me a better way to solve this question.

Hi @mananaroramail,
Your code is giving wrong answer for the following inputs:
1
abc

1
abcd

Kindly review your code. Do a dry run. Also first try to get all the sub-sequences and then think about the Lexicographical order.

Ok , I got the mistake.
Now it’s working properly.
But I just wanna know if there’s a better approach to deal with this question

Hey @mananaroramail,
You can put all the sub sequences in an arraylist and then sort the arraylist using a comparator.

Do you mean .compareTo() function or something else ??

@mananaroramail
Yes .compareTo() function