Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Subsequences of String

Moderate
0/80
Average time to solve is 15m
profile
Contributed by
204 upvotes
Asked in companies
AmazonCiscoShareChat

Problem statement

You are given a string 'STR' containing lowercase English letters from a to z inclusive. Your task is to find all non-empty possible subsequences of 'STR'.

A Subsequence of a string is the one which is generated by deleting 0 or more letters from the string and keeping the rest of the letters in the same order.
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 10 
1 <=  |STR| <= 16

Where |STR| represents the length of the string 'STR'.

Time Limit: 1 sec
Sample Input 1:
1 
abc
Sample Output 1:
a ab abc ac b bc c
Explanation of sample input 1:
All possible subsequences of abc are :  
“a” , “b” , “c” , “ab” , “bc” , “ac”, “abc”
Sample Input 2:
1
bbb
Sample Output 2:
b b b bb bb bb bbb
Full screen
Console