DSA interview question
A search engine's autocomplete test generates every subsequence of a query string (characters in their original order, not necessarily contiguous) to check fuzzy matching. For "abc" that's abc, ab, ac, a, bc, b, c and the empty string: 2ⁿ in total. This is the template behind a whole family of recursion problems. At each index, decide whether to pick the character or skip it, and act when the index reaches the end. Small changes to that template give "print all subsequences with property P", "stop at the first one found" (return a bool), and "count them" (return a number).
Example: "abc" → "abc" "ab" "ac" "a" "bc" "b" "c" "".
vector<string> allSubsequences(const string& s); // pick-then-skip order; 2^n strings
| Input | Output (pick-then-skip order) | Explanation |
|---|---|---|
"abc" | "abc" "ab" "ac" "a" "bc" "b" "c" "" | 2³ = 8 |
"ab" | "ab" "a" "b" "" | |
"aa" | "aa" "a" "a" "" | Different positions, so both copies of "a" appear |
"a" | "a" "" | |
"" | "" | Only the empty subsequence |
(Confirm: a subsequence keeps the original order; the empty subsequence counts; duplicates from repeated characters are kept.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in