Problem · String
Sorted Subsets of a String
Learn this problemProblem statement
Given a string s containing distinct lowercase English letters, return every subset of its characters.
Represent each subset as a string whose characters are in ascending order. Include the empty subset as the empty string, and return the complete list in lexicographic order.
Function
generateSubsets(s: String) → String[]Examples
Example 1
s = "abc"return = ["","a","ab","abc","ac","b","bc","c"]The eight strings represent all subsets. Every string is internally sorted, and the list is lexicographically sorted.
Example 2
s = "ba"return = ["","a","ab","b"]The input order does not affect the canonical representation or result ordering.
Example 3
s = ""return = [""]The empty string has exactly one subset: the empty subset.
Constraints
0 <= s.length <= 16scontains distinct lowercase English letters.