[ INFO ]category: Coding difficulty: medium freq: Must first seen: 2026-03-13
[MEDIUM][CODING][MUST]
$catproblem.md
Practice/Google/Leetcode 1092. Shortest Common Supersequence
Leetcode 1092. Shortest Common Supersequence
CodingMust
Problem
Given two strings, find the shortest string that contains both input strings as subsequences. A subsequence is a sequence derived from another string by deleting some or no characters without changing the order of the remaining characters.
Your goal is to merge the two strings in a way that minimizes the total length while ensuring both original strings can be formed by removing characters from the result.
Requirements
Return the shortest possible string that contains both input strings as subsequences
If multiple valid answers exist with the same length, return any one of them
Both input strings consist only of lowercase English letters
The solution should preserve the relative order of characters from both input strings
Constraints
1 ≤ str1.length, str2.length ≤ 1000
str1 and str2 consist of lowercase English letters only
Expected time complexity: O(n × m) where n and m are the lengths of the input strings