


[“a”], [“ab”], [“abc”], [“ac”], [“b”], [“bc”], [“c”]
The first line of input contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first and the only line of each test case contains a string ‘STR’.
For each test case, print all the possible subsequences of the given string ‘STR’ in lexicographically sorted order.
Print the output of each test case in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 100
1 <= |STR| <= 10
Where |STR| represents the length of ‘STR’.
Time Limit: 1 sec
Approach: The basic idea is to generate all the subsequences of the ‘STR’ and store all the strings in the array/list. Then we can simply sort the array/list to get all subsequences in lexicographically increasing order.
To generate all the subsequences, we will use bit patterns from binary representation of 1 to (2 ^ ‘|STR|’) – 1. here ‘|STR|’ represents the length of ‘STR’.
For example: For ‘STR’ = “abc”
Append characters from the input string that corresponds to the bit value 1 in binary representation to the string subsequence.
Here is the complete algorithm: