Microsoft interview question
List all non-empty subsequences of a string in alphabetical order
- Company:
- Microsoft
- Type:
- Coding
- Difficulty:
- Easy
- Reported:
- November 15, 2026
Problem
A subsequence is obtained by deleting zero or more characters from a string while keeping the original order of the remaining characters.
Implement build_subsequences(s) that returns an array of all non-empty subsequences of s, sorted in alphabetically ascending order.
Example 1
Input: s = "xyz"
Output: ["x", "xy", "xyz", "xz", "y", "yz", "z"]
These are all 7 non-empty subsequences of "xyz" in lexicographic order.
Example 2
Input: s = "ba"
Output: ["a", "b", "ba"]
"ab" is not a subsequence because order must be preserved.
Constraints
- 1 <= len(s) <= 16
sconsists of distinct lowercase English letters (a to z).
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern