Reported September 2026
Infosysbacktracking

Enumerate All Subsequences

Reported by candidates from Infosys's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Infosys OA. Under 2s to a working solution.
Founder's read

The edge case that breaks a naive solution on this Infosys OA, reported in September 2026, is duplicates. Feed it "aa" and a lazy Set-based approach returns three strings instead of four. The task is to enumerate every subsequence of a string up to length 10, empty string included, and sort them lexicographically. It's a backtracking problem with a trap in the wording. If you're taking this OA in the next day or two, know the trap before you start. StealthCoder is the safety net running invisibly during the live assessment if you blank, but you shouldn't need it for this one.

The problem

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.
s contains only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is backtracking, or a bitmask over 2^n index subsets. With n at most 10 you get at most 1024 subsequences, so brute force is fine. For each index, choose include or exclude, and push the built string at the leaf. Or loop mask from 0 to 2^n - 1 and build a string from the set bits. The pitfall is dedup. The problem says different index subsets are distinct even when the strings match, so "aa" must return two copies of "a". Don't use a Set. Second pitfall: the empty string must be in the output, and it sorts first. Then sort the final array with default string comparison, which is lexicographic for lowercase letters. Also handle s of length 0, which should return [""], not an empty array. StealthCoder is there as a hedge in the live OA if the mask logic slips, but the whole solution is about fifteen lines.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Enumerate All Subsequences cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Infosys's OA.

Infosys reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Enumerate All Subsequences FAQ

What's the trick in Enumerate All Subsequences?+

Don't dedupe. The statement says different index subsets count as distinct even when the strings match, so "aa" returns ["","a","a","aa"]. Generate all 2^n subsets with recursion or a bitmask, collect every string, then sort. Using a Set is the one mistake that fails the duplicate test.

How hard is this problem really?+

Easy to medium. The length cap of 10 means brute force passes with no optimization. The difficulty is reading the duplicate rule and handling the empty string and the empty input. If you've written a subsets generator before, you can finish it in a few minutes.

What should I return when s is empty?+

Return an array containing a single empty string, [""]. The empty string is a valid subsequence of any string, including an empty one. Returning an empty array is a common bug and will fail the edge case test.

Do I need to sort the output, and how?+

Yes. Sort in non-decreasing lexicographic order. Since the input is only lowercase letters, the default string sort in most languages works. The empty string comes first, and a prefix like "a" comes before "ab". Duplicates sit next to each other after sorting.

How do I prepare for this in 48 hours?+

Write the include-or-exclude recursion and the bitmask version from scratch once each. Test on "abc", "aa", and the empty string. Then do two or three related subsets and permutations problems. This Infosys question tests careful reading more than advanced technique, so practice checking the examples against your output.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Infosys.

OA at Infosys?
Invisible during screen share
Get it