You are given N comma-separated Strings. You need to form all possible legal subsets of these N strings. These subsets will be a combination of zero or more of these N Strings. After forming the subsets, they will be ranked in a particular order. The legal subset formation and ranking logic is as described below
. Rank 1 will always be an empty set
– Next N ranks will be the N Strings that appear in the order they are provided in the input
• After N + 1 ranks, you need to combine N strings such that all legal combinations are formed
Legal combination simply means that while combinations are formed, the string that appears to the left of a particular string in the input, can never appear to the right of that particular string, when subsets are formed
. A subset with less elements will be ranked higher than a subset with more elements (NOTE: – Rank 1 is higher than rank 2)
. Refer Example 2 to get a better understanding of how subsets are formed and ranked
It is guaranteed that
– N=1
• All N strings are unique
Example you are having an input string “aa,cc,bb”. In this string we can see we have three strings which are comma separated. Now from this group of string we have to create all possible subset of strings. 8 subsets can be formed from these strings. And they are as follows:
1:0
2: (aa)
3: (cc)
4: (bb)
5: (aa,cc)
6: (aa,bb)
7: (cc,bb)
8: (aa,cc,bb)
Note: here we can see the ranks given to the subsets are first by size i.e., the subset with lesser number of strings is ranked higher than the subset with hi size. If the subsets have equal number of strings then, the combination which is formed earlier (by virtue of combining strings in order they appear in input) a higher rank.
For example, rank of subset (aa,cc) > rank of (aa,bb) because string co is appearing prior to string bb in the input. Similarly, rank of (be) ankit (bb).
You are provided one rank R and for that you have to print the Rh subset from all legal subsets.