Given two strings X and Y of lengths m and n respectively, find the length of the smallest string which has both, X and Y as its sub-sequences.
Note: X and Y can have both uppercase and lowercase letters.
Input: X = abcd, Y = xycd Output: 6 Explanation: Shortest Common Supersequence would be abxycd which is of length 6 and has both the strings as its subsequences.
Input: X = efgh, Y = jghi Output: 6 Explanation: Shortest Common Supersequence would be ejfghi which is of length 6 and has both the strings as its subsequences.
Complete shortestCommonSupersequence() function that takes X, Y, m, and n as arguments and returns the length of the required string.
Expected Time Complexity: O(Length(X) * Length(Y)).
Expected Auxiliary Space: O(Length(X) * Length(Y)).
1<= |X|, |Y| <= 100
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes