Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 1092 Shortest Common Supersequence - Problem Statement

LeetCode 1092

This is Shortest Common Supersequence from LeetCode. Given two strings, find the shortest string that has both as subsequences. For "abac" and "cab", the answer is "cabac". This is the inverse of LCS.

Instead of finding the longest common part, you're building the shortest string containing both. The minimum length equals s+tLCS(s,t)|s| + |t| - \text{LCS}(s, t). Find the LCS first, then reconstruct the supersequence.