Cody

Problem 45474. Sub-sequence - 02

Solution 2231903

Submitted on 24 Apr 2020 by bainhome
  • Size: 61
  • This is the leading solution.
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
a=[1,1,1,1,1,2,3,1,4] b=[2,3,0,0,9,5,4,1] assert(isequal(longest_sub_common(a,b),3))

a = 1 1 1 1 1 2 3 1 4 b = 2 3 0 0 9 5 4 1

2   Pass
a=[1,1,1,1,1,2,3] b=[2,3,0,0,9,5,4,1] assert(isequal(longest_sub_common(a,b),2))

a = 1 1 1 1 1 2 3 b = 2 3 0 0 9 5 4 1

3   Pass
a=[1,1,1,1,1,2,3,1,4] b=zeros(1,500); assert(isequal(longest_sub_common(a,b),0))

a = 1 1 1 1 1 2 3 1 4

4   Pass
a=[1,1,1,1,1,2,3,1,4] b=[zeros(1,50),ones(1,200),ones(1,20)*3] assert(isequal(longest_sub_common(a,b),6))

a = 1 1 1 1 1 2 3 1 4 b = Columns 1 through 29 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 30 through 58 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Columns 59 through 87 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 88 through 116 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 117 through 145 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 146 through 174 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 175 through 203 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 204 through 232 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 233 through 261 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 Columns 262 through 270 3 3 3 3 3 3 3 3 3

5   Pass
a='aaabbbcccxyz' b='abcyycbaabc' assert(isequal(longest_sub_common(a,b),5))

a = 'aaabbbcccxyz' b = 'abcyycbaabc'

6   Pass
a=[10 9 8 2 4 2 1 4 7 7 6 5 3 6 8 8 6 8 7 2 6 4 1 2 2 7 5 7 3 1 6 3 10 10 4 1 7 9 10 1 5 6 7 8 7 8 4 6 2 1 10 3 6 10 2 2 4 10 4 3 2 4 4 2 5 1 7 1 6 8 3 5 6 1 5 7 3 9 10 9 6 3 8 3 10 7 7 2 1 3 9 10 7 8 3 6 9 5 10 1 4 6 1 8 6 6 9 9 8 4 5 8 2 2 3 6 10 8 4 3 9 10 7 3 1 9 6 10 1 6 3 9 2 5 4 9 7 3 4 2 7 6 2 2 5 10 6 1 1 9 5 4 8 4 6 8 9 4 7 10 1 6 5 4 3 8 10 2 8 2 10 9 5 8 5 9 4 1 6 10 2 5 8 1 10 8 6 2 5 6 10 9 10 7 5 10 5 3 4 8 6 8 10 10 6 10 2 1 4 6 6 10 6 5 6 8 1 9 2 5 3 4 7 2 3 2 2 4 9 5 5 2 10 5 9 7 4 9 8 5 9 9 5 4 6 10 8 4 8 10 6 6 4 1 2 1 5 1 10 7 1 1 3 5 2 1 8 4 8 5 5 1 1 1 6 3 9 9 10 5 3 3 6 8 4 5 7 10 2 8 6 5 9 4 2 7 7 4 9 10 10 2 3 1 7 2 5 9 6 4 3 5 10 2 5 9 1 7 10 3 2 7 10 7 9 2 8 4 5 2 9 7 8 9 1 10 5 8 8 9 2 5 7 10 9 9 6 6 9 1 9 5 1 8 2 2 7 3 4 5 5 4 7 2 2 1 4 8 3 8 7 9 9 3 4 6 4 9 9 6 3 7 3 5 4 6 10 8 10 3 6 1 8 7 9 10 10 5 1 6 3 3 4 1 8 8 6 4 9 6 10 9 4 6 4 7 8 8 2 9 1 5 8 8 4 8 9 3 2 3 4 3 10 1 6 2 9 2 6 10 4 1 3 4 4 3 10 7 10 5 10 1 7 9 3 10 8 9 6 8 4 3 4 6 9 3 5 9 7 10 3 9 7 3 5 4 6 9 2 9 9 4 5 6 8 8 8 4 5 10 6 9 3 7 6 10 1 6 6 1] b=[14 14 7 12 3 10 4 7 13 3 5 8 6 12 15 3 4 11 6 15 15 10 13 7 10 15 9 15 11 8 10 14 3 6 15 7 10 14 15 10 2 1 10 9 15 12 10 8 4 15 9 1 11 8 1 14 5 4 2 5 4 10 1 5 5 14 7 12 10 12 2 15 13 1 7 5 10 4 9 10 9 7 1 8 7 2 7 7 9 13 11 14 1 4 7 15 12 7 6 1 12 8 3 7 3 12 6 15 1 13 10 9 10 11 2 14 1 5 3 14 2 9 10 10 13 1 13 8 11 4 9 11 15 7 2 1 10 12 11 6 15 8 15 2 4 12 14 12 5 3 13 12 5 4 5 13 13 9 9 5 11 12 7 7 7 5 11 14 14 12 4 11 2 2 3 3 9 2 13 11 14 8 10 14 9 5 15 1 5 15 6 5 2 14 3 5 14 8 10 9 11 1 8 1 13 6 13 4 9 15 1 1 1 11 9 2 12 10 2 2 3 12 2 4 4 2 13 11 12 10 8 5 10 2 3 1 15 15 2 8 10 5 12 9 7 5 12 14 11 7] assert(isequal(longest_sub_common(a,b),121))

a = Columns 1 through 29 10 9 8 2 4 2 1 4 7 7 6 5 3 6 8 8 6 8 7 2 6 4 1 2 2 7 5 7 3 Columns 30 through 58 1 6 3 10 10 4 1 7 9 10 1 5 6 7 8 7 8 4 6 2 1 10 3 6 10 2 2 4 10 Columns 59 through 87 4 3 2 4 4 2 5 1 7 1 6 8 3 5 6 1 5 7 3 9 10 9 6 3 8 3 10 7 7 Columns 88 through 116 2 1 3 9 10 7 8 3 6 9 5 10 1 4 6 1 8 6 6 9 9 8 4 5 8 2 2 3 6 Columns 117 through 145 10 8 4 3 9 10 7 3 1 9 6 10 1 6 3 9 2 5 4 9 7 3 4 2 7 6 2 2 5 Columns 146 through 174 10 6 1 1 9 5 4 8 4 6 8 9 4 7 10 1 6 5 4 3 8 10 2 8 2 10 9 5 8 Columns 175 through 203 5 9 4 1 6 10 2 5 8 1 10 8 6 2 5 6 10 9 10 7 5 10 5 3 4 8 6 8 10 Columns 204 through 232 10 6 10 2 1 4 6 6 10 6 5 6 8 1 9 2 5 3 4 7 2 3 2 2 4 9 5 5 2 Columns 233 through 261 10 5 9 7 4 9 8 5 9 9 5 4 6 10 8 4 8 10 6 6 4 1 2 1 5 1 10 7 1 Columns 262 through 290 1 3 5 2 1 8 4 8 5 5 1 1 1 6 3 9 9 10 5 3 3 6 8 4 5 7 10 2 8 Columns 291 through 319 6 5 9 4 2 7 7 4 9 10 10 2 3 1 7 2 5 9 6 4 3 5 10 2 5 9 1 7 10 Columns 320 through 348 3 2 7 10 7 9 2 8 4 5 2 9 7 8 9 1 10 5 8 8 9 2 5 7 10 9 9 6 6 Columns 349 through 377 9 1 9 5 1 8 2 2 7 3 4 5 5 4 7 2 2 1 4 8 3 8 7 9 9 3 4 6 4 Columns 378 through 406 9 9 6 3 7 3 5 4 6 10 8 10 3 6 1 8 7 9 10 10 5 1 6 3 3 4 1 8 8 Columns 407 through 435 6 4 9 6 10 9 4 6 4 7 8 8 2 9 1 5 8 8 4 8 9 3 2 3 4 3 10 1 6 Columns 436 through 464 2 9 2 6 10 4 1 3 4 4 3 10 7 10 5 10 1 7 9 3 10 8 9 6 8 4 3 4 6 Columns 465 through 493 9 3 5 9 7 10 3 9 7 3 5 4 6 9 2 9 9 4 5 6 8 8 8 4 5 10 6 9 3 Columns 494 through 500 7 6 10 1 6 6 1 b = Columns 1 through 29 14 14 7 12 3 10 4 7 13 3 5 8 6 12 15 3 4 11 6 15 15 10 13 7 10 15 9 15 11 Columns 30 through 58 8 10 14 3 6 15 7 10 14 15 10 2 1 10 9 15 12 10 8 4 15 9 1 11 8 1 14 5 4 Columns 59 through 87 2 5 4 10 1 5 5 14 7 12 10 12 2 15 13 1 7 5 10 4 9 10 9 7 1 8 7 2 7 Columns 88 through 116 7 9 13 11 14 1 4 7 15 12 7 6 1 12 8 3 7 3 12 6 15 1 13 10 9 10 11 2 14 Columns 117 through 145 1 5 3 14 2 9 10 10 13 1 13 8 11 4 9 11 15 7 2 1 10 12 11 6 15 8 15 2 4 Columns 146 through 174 12 14 12 5 3 13 12 5 4 5 13 13 9 9 5 11 12 7 7 7 5 11 14 14 12 4 11 2 2 Columns 175 through 203 3 3 9 2 13 11 14 8 10 14 9 5 15 1 5 15 6 5 2 14 3 5 14 8 10 9 11 1 8 Columns 204 through 232 1 13 6 13 4 9 15 1 1 1 11 9 2 12 10 2 2 3 12 2 4 4 2 13 11 12 10 8 5 Columns 233 through 250 10 2 3 1 15 15 2 8 10 5 12 9 7 5 12 14 11 7

7   Pass
a='aaabaaabaaabaaa' b='abababababa' assert(isequal(longest_sub_common(a,b),9))

a = 'aaabaaabaaabaaa' b = 'abababababa'

Suggested Problems

More from this Author149

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!