Solution: Shortest Common Supersequence
Explore how to compute the shortest common supersequence (SCS) of two strings by mastering dynamic programming techniques. Understand the connection between SCS and the longest common subsequence (LCS) and learn to build solutions that efficiently combine shared and unique characters from both strings. This lesson guides you through constructing a DP table and reconstructing the optimal supersequence to solve the problem effectively.
We'll cover the following...
Statement
You are given two strings, str1 and str2. Your task is to find the shortest common supersequence (SCS). The shortest possible string that contains both str1 and str2 as subsequences.
If multiple strings satisfy this condition, you may return any one of them.
Note: A string
is considered a subsequence of another string if can be obtained by deleting zero or more characters from without changing the order of the remaining characters.
Constraints:
str1.length,str2.length...