13. Shortest Common Supersequence
Last updated
Last updated
The problem can be found at the following link: Question Link
The idea behind this question is to find the longest common part in two sequences. The longest string we can make is of size m+n, but when we take away the common subsequence part, we get the smallest possible string after putting them together in the same order.
To find the shortest common supersequence of two strings X
and Y
,
I use the concept of the Longest Common Subsequence (LCS).
The idea is to find the LCS of the two strings and then subtract it from the sum of the lengths of the two strings.
Time Complexity: O(m * n)
, where m and n are the lengths of strings X
and Y
, respectively.
Auxiliary Space Complexity: O(m * n)
, where m
and n
are the lengths of strings X
and Y
, respectively.
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.