As reported: PayPal Engineer Full Stack, system design round (2025), which also had one DSA question: generate all subsequences of a string in lexicographic order.
A subsequence keeps some characters of s in their original order (not necessarily adjacent). Return all distinct non-empty subsequences of s, sorted lexicographically.
Example 1
s = "abc" -> ["a","ab","abc","ac","b","bc","c"]
Example 2
s = "aab" -> ["a","aa","aab","ab","b"]
Constraints: 1 ≤ s.length ≤ 12; lowercase English letters.
Code runner format: one line, s as a JSON string. Implement sortedSubsequences(s); the harness prints the list.
Clarifications
- Equal subsequences coming from different positions are listed once (
"aab"has two ways to make"a"and"ab"). - The empty subsequence is not included.