New update is available. Click here to update.

Ninja and Strings

Posted: 10 Mar, 2021
Difficulty: Moderate

PROBLEM STATEMENT

Try Problem

Ninja has been given a string ‘STR’ containing lowercase english alphabets. He wants to generate all the possible subsequences of the ‘STR’ in lexicographically sorted order.

For example: For ‘STR’ = “abc” following are the subsequences in lexicographically sorted order:

[“a”], [“ab”], [“abc”], [“ac”], [“b”], [“bc”], [“c”]

Ninja is busy with some other task so he asks you for help.

Can you help Ninja to generate all the possible subsequences of the given string ‘STR’ in lexicographically sorted order?

Input Format:
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’.
Output Format :
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.

Note:

You do not need to print anything; it has already been taken care of. Just implement the given function.
Constraints:
1 <= ‘T’ <= 100
1 <= |STR| <= 10 

Where |STR| represents the length of ‘STR’.

Time Limit: 1 sec