Power Set
Submissions: 2828   Accuracy:

23.85%

  Difficulty: Easy   Marks: 2

Given a string of length n, print all the possible subsets of the string in a lexiographically-sorted order.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer n denoting the length of the string.
The second line of each test case contains the string consisting of lower-case english alphabets.

Output:
For each testcase, in a new line, print all the possible subsets (except the null subset) in a sorted order with a space between each subset.

Constraints:
1<= T <=100
1<= n <=16

Example:
Input:
1
3
abc
Output:
a ab abc ac b bc c

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sujnesh Mishra
Author: sujnesh


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.