DSA interview question
You're on a team building a "merge conflict resolver" for a lightweight version-control-like tool. Two collaborators independently edited a shared line of text, producing strings str1 and str2. Instead of forcing a manual merge, your job is to auto-generate the shortest possible merged string such that both str1 and str2 are subsequences of it — meaning both people's edits are "contained" within the merged result without reordering their characters. Return that shortest common supersequence (SCS) string itself, not just its length.
string shortestCommonSupersequence(string str1, string str2);
str1 | str2 | One valid output | Explanation |
|---|---|---|---|
"abac" | "cab" | "cabac" | length 5; both "abac" and "cab" are subsequences of it |
"geek" | "eke" | "geeke" | length 5 |
"abc" | "abc" | "abc" | identical strings → SCS is just the string itself |
"abc" | "" | "abc" | supersequence of empty string is the other string |
"" | "" | "" | trivial |
"ab" | "ba" | "aba" or "bab" | length 3, multiple valid answers exist — any correct one is accepted |
(Always clarify: many valid SCS strings can exist for the same length — interviewer usually only checks the LENGTH matches optimal, not exact string, unless stated.)
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