You're given two strings str1 and str2, and your task is to find the shortest possible string that contains both strings as subsequences.
A subsequence is formed by deleting some (possibly zero) characters from a string while maintaining the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde".
The shortest common supersequence is the smallest string that has both input strings as subsequences. Think of it as merging two strings optimally while preserving their character order.
Example: For strings "abac" and "cab", one possible shortest common supersequence is "cabac" (length 5), which contains both "abac" and "cab" as subsequences.
Goal: Return any valid shortest common supersequence. If multiple solutions exist with the same minimum length, any of them is acceptable.
Input & Output
Constraints
- 1 โค str1.length, str2.length โค 1000
- str1 and str2 consist of lowercase English letters only
- Important: Multiple valid answers may exist - return any shortest one