1329. Power Set Using Bitmask

MediumBit ManipulationBitmaskSubsetsString

Given a string s, generate all distinct non-empty subsequences of s using bitmask enumeration, and return them sorted in lexicographic order. A subsequence keeps the original relative order of the chosen characters. Duplicate subsequences (possible when s has repeated characters) appear only once.

Input: A JSON object {"s": <string of lowercase letters>}.

Output: Return the sorted list of distinct non-empty subsequences.

Examples

Example 1
Input: {"s":"ab"}
Output: ["a","ab","b"]
Explanation: Subsequences a, b, ab sorted lexicographically.
Example 2
Input: {"s":"aa"}
Output: ["a","aa"]
Explanation: Duplicates collapse to a and aa.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →