All Possible Subsequences of a String
Learn how to print all the possible subsequences of a string using Recursion.
We'll cover the following
Problem statement
Given a string, find out all its subsequences.
A string is a subsequence of a given string that is generated by deleting some character of a given string without changing its order.
For example, if you have an input string as abc
, the subsequences of this string can be a
, b
, c
, ab
, ac
, bc
, abc
.
Solution: Recursive approach
One by one, fix characters and recursively generate all subsets starting from them. After every recursive call, we remove the last character so that the next permutation can be generated. Let’s now move on to the implementation now.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.