Practice Shortest Common Supersequence
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.
Source: Shortest Common Supersequence on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
str1 = "abac", str2 = "cab"
Output
"cabac"
# Example 2
Input
str1 = "aaaaaaaa", str2 = "aaaaaaaa"
Output
"aaaaaaaa"
Constraints
1 <= str1.length, str2.length <= 1000
str1 and str2 consist of lowercase English letters.
Related LeetCode Problems
Practice more problems similar to Shortest Common Supersequence .
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.