Challenge: Shortest Common Supersequence(SCS)
Given two strings, let's write a function to find their shortest common supersequence.
We'll cover the following
Problem statement
Given two strings, write a function to find the length of their shortest common superstring. A superstring is a string which has both input strings as substrings.
Input
Two strings
Output
The length of their shortest common supersequence
Sample input
s1 = "abcf"
s2 = "bdcf"
Sample output
The shortest common supersequence of the two strings above will be abdcf
and the following would be the output:
result = 5
Coding challenge
First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good luck!
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.