Cody

Problem 2361. Find the longest match inside two strings

Solution 2741917

Submitted on 26 Jul 2020 by Masato Kanematsu
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
first = 'minimum'; second = 'maximum'; match = substrmatch( first, second ); assert( strcmp( match, 'imum' ) )

2   Pass
first = 'aabbcc'; second = 'abc'; match = substrmatch( first, second ); assert( strcmp( match, 'ab' ) || strcmp( match, 'bc' ) )

3   Pass
first = 'MATLAB'; second = 'LAPACK'; match = substrmatch( first, second ); assert( strcmp( match, 'LA' ) )

4   Pass
first = 'abc'; second = 'def'; match = substrmatch( first, second ); assert( strcmp( match, '' ) )

5   Pass
first = 'banana'; second = 'anagram'; match = substrmatch( first, second ); assert( strcmp( match, 'ana' ) )

6   Pass
first = 'string within a string'; second = 'within'; match = substrmatch( first, second ); assert( strcmp( match, 'within' ) )

7   Pass
first = 'yes and no'; second = 'ankles and noses'; match = substrmatch( first, second ); assert( strcmp( match, 'es and no' ) )

8   Pass
first = 'three apples'; second = 'one apple'; match = substrmatch( first, second ); assert( strcmp( match, 'e apple' ) )

9   Pass
first = 'hello there'; second = 'jello that'; match = substrmatch( first, second ); assert( strcmp( match, 'ello th' ) )