...

/

Shortest Common Supersequence of Two Strings

Shortest Common Supersequence of Two Strings

Take your dynamic programming skills to the next level by solving this string-based problem.

Problem statement

Given two strings str1 and str2, return the shortest string (supersequence) that has both str1 and str2 as subsequences. If multiple answers exist, you may return any of them.

A string S is a subsequence of string T if deleting some number of characters from T (possibly 0, and the characters are chosen anywhere from T) results in the string S.

Let’s look at the following example:

  • We have two strings, str1 = apple and str2 = les. The SCS of ...