Search⌘ K
AI Features

Solution: Shortest Common Supersequence

Understand how to compute the shortest common supersequence of two strings by applying dynamic programming. Explore constructing a solution using longest common subsequence logic, building a DP table, and reconstructing the final minimal sequence that includes both input strings as subsequences.

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 ss is considered a subsequence of another string tt if ss can be obtained by deleting zero or more characters from tt without changing the order ...