Solution: Shortest Common Supersequence
Explore how to solve the shortest common supersequence problem using dynamic programming. Understand the relationship between the longest common subsequence and supersequence to efficiently build the shortest string containing both input strings as subsequences. Learn to construct a DP table, trace back to form the solution, and analyze time and space complexities in this step-by-step lesson.
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...