The Shortest Common Supersequence interview question asks you to find the shortest string that has both str1 and str2 as subsequences. Unlike the LCS (longest common subsequence) which removes characters, this problem builds the minimal string containing both. The SCS length = len(str1) + len(str2) - LCS_length. Reconstructing the actual string requires backtracking through the LCS DP table.
Microsoft, Meta, Amazon, Google, and Bloomberg ask this HARD string DP problem because it builds directly on LCS — a foundational dynamic programming problem — but adds the reconstruction step. Finding the SCS length is straightforward; building the actual shortest supersequence from the DP table tests candidates' ability to trace DP decisions. This models DNA sequence merging, file merge conflict resolution, and edit distance reconstruction.
The pattern is LCS DP with string reconstruction. Build the standard LCS table dp[i][j] = length of LCS of str1[:i] and str2[:j]. Then reconstruct the SCS by backtracking: if str1[i-1] == str2[j-1], add that character once and move diagonally. If dp[i-1][j] > dp[i][j-1], add str1[i-1] and move up. Otherwise, add str2[j-1] and move left. After exhausting one string, append the remaining characters of the other.
str1 = "ace", str2 = "abcde".
LCS = "ace" (length 3).
SCS length = 3 + 5 - 3 = 5.
Reconstruction:
SCS: "abcde".
str1[i-1] != str2[j-1], you must add the character from the direction of the larger dp value.For the Shortest Common Supersequence coding problem, the string dynamic programming interview pattern is the core skill. The SCS length formula (sum of both lengths minus LCS length) is the key mathematical insight. Bloomberg and Dream11 interviewers test the backtracking step — practice tracing through the DP table with a small example before coding. The SCS reconstruction is closely related to edit distance path reconstruction — master both backtracking patterns together as they use the same DP table traversal logic.