Subsequences of String Problem Statement

You are provided with a string 'STR' that consists of lowercase English letters ranging from 'a' to 'z'. Your task is to determine all non-empty possible subsequences of the string 'STR'.

Explanation:

A subsequence of a string is derived by deleting zero or more characters from the string while maintaining the order of the remaining characters.

Input:

The first line of input consists of an integer 'T' representing the number of test cases. Each test case contains one line, which holds the string 'STR'.

Output:

For each test case, print the subsequences of the string 'STR' separated by space. Each test case's output must be printed on a separate line. The order of output subsequences can vary.

Example:

Input:
2
abc
ab
Output:
a ab ac abc b bc c
a ab b

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ |STR| ≤ 16
  • Where |STR| denotes the length of the string 'STR'.

Note:

You do not need to print anything; the output functionality is already handled. Only implement the function to generate the required subsequences.
AnswerBot
4mo

Generate all possible subsequences of a given string.

  • Use recursion to generate all possible subsequences by including or excluding each character in the string.

  • Maintain the order of characters while g...read more

Help your peers!
Select
Add answer anonymously...

Amazon Software Developer Intern interview questions & answers

A Software Developer Intern was asked 4mo agoQ. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ. Given a matrix, find the shortest distance between two given points located anyw...read more
A Software Developer Intern was asked 4mo agoQ. For a given array, how would you count the number of inversions?

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 4mo agoQ1. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ2. Given a matrix, find the shortest distance between two given points located anyw...read more
A Software Developer Intern was asked 4mo agoQ3. For a given array, how would you count the number of inversions?
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits