Problem · String
Enumerate All Subsequences
Learn this problemProblem statement
You are given a string s of lowercase English letters.
A subsequence is formed by deleting zero or more characters from s without changing the order of the remaining characters. Different index subsets are distinct subsequences even when they produce the same string.
Return every subsequence of s, including the empty string, as an array of strings sorted in non-decreasing lexicographic order.
Function
allSubsequences(s: String) → String[]Examples
Example 1
s = "abc"return = ["","a","ab","abc","ac","b","bc","c"]The eight index subsets of abc produce these strings. Lexicographic order places the empty string first.
Example 2
s = "aa"return = ["","a","a","aa"]The two single-character subsequences both equal a and both appear.
Constraints
0 <= s.length <= 10.scontains only lowercase English letters.