Two strings are given. Find the longest common substring between them. The substring characters need not be adjacent. They, however, must appear in same order in both input strings.
Example:
str1 = 'abcdefghi'; str2 = 'zazbzczd';
output = 'abcd'
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers46
Suggested Problems
-
The Goldbach Conjecture, Part 2
2412 Solvers
-
967 Solvers
-
Convert hex color specification to MATLAB RGB
253 Solvers
-
Add a row of zeros on top of a matrix
266 Solvers
-
String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values
1956 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Shouldn't there be two spaces between example and a in y_correct in test 4?
right.. corrected. Thanks :)
perhaps add another test to avoid non-general solutions? (e.g. str1='abaa' str2='aaab' should return 'aaa')
For test 5:
str1 = 'a string with many characters';
str2 = 'zzz zzz zzz zzz zzz';
Why wouldn't the correct answer be four spaces instead of just one?