Cody

# Problem 15. Find the longest sequence of 1's in a binary sequence.

Solution 2026918

Submitted on 18 Nov 2019 at 22:20 by Normand MacLaurin
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
x = '0'; y_correct = 0; assert(isequal(lengthOnes(x),y_correct))

len = 1 x = '0' y = 0

2   Pass
x = '1'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

len = 1 x = '1' k = 2 n = 1 m = 1 y = 1

3   Pass
x = '01'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

len = 2 x = '01' k = 3 n = 1 m = 1 y = 1

4   Pass
x = '10'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

len = 2 x = '10' k = 2 n = 1 m = 1 y = 1

5   Pass
x = '00'; y_correct = 0; assert(isequal(lengthOnes(x),y_correct))

len = 2 x = '00' y = 0

6   Pass
x = '11'; y_correct = 2; assert(isequal(lengthOnes(x),y_correct))

len = 2 x = '11' k = 2 n = 1 k = 3 n = 2 m = 2 k = 3 n = 1 y = 2

7   Pass
x = '1111111111'; y_correct = 10; assert(isequal(lengthOnes(x),y_correct))

len = 10 x = '1111111111' k = 2 n = 1 k = 3 n = 2 k = 4 n = 3 k = 5 n = 4 k = 6 n = 5 k = 7 n = 6 k = 8 n = 7 k = 9 n = 8 k = 10 n = 9 k = 11 n = 10 m = 10 k = 3 n = 1 k = 4 n = 2 k = 5 n = 3 k = 6 n = 4 k = 7 n = 5 k = 8 n = 6 k = 9 n = 7 k = 10 n = 8 k = 11 n = 9 k = 4 n = 1 k = 5 n = 2 k = 6 n = 3 k = 7 n = 4 k = 8 n = 5 k = 9 n = 6 k = 10 n = 7 k = 11 n = 8 k = 5 n = 1 k = 6 n = 2 k = 7 n = 3 k = 8 n = 4 k = 9 n = 5 k = 10 n = 6 k = 11 n = 7 k = 6 n = 1 k = 7 n = 2 k = 8 n = 3 k = 9 n = 4 k = 10 n = 5 k = 11 n = 6 k = 7 n = 1 k = 8 n = 2 k = 9 n = 3 k = 10 n = 4 k = 11 n = 5 k = 8 n = 1 k = 9 n = 2 k = 10 n = 3 k = 11 n = 4 k = 9 n = 1 k = 10 n = 2 k = 11 n = 3 k = 10 n = 1 k = 11 n = 2 k = 11 n = 1 y = 10

8   Pass
x = '100101011111010011111'; y_correct = 5; assert(isequal(lengthOnes(x),y_correct))

len = 21 x = '100101011111010011111' k = 2 n = 1 m = 1 k = 5 n = 1 k = 7 n = 1 k = 9 n = 1 k = 10 n = 2 k = 11 n = 3 k = 12 n = 4 k = 13 n = 5 m = 5 k = 10 n = 1 k = 11 n = 2 k = 12 n = 3 k = 13 n = 4 k = 11 n = 1 k = 12 n = 2 k = 13 n = 3 k = 12 n = 1 k = 13 n = 2 k = 13 n = 1 k = 15 n = 1 k = 18 n = 1 k = 19 n = 2 k = 20 n = 3 k = 21 n = 4 k = 22 n = 5 k = 19 n = 1 k = 20 n = 2 k = 21 n = 3 k = 22 n = 4 k = 20 n = 1 k = 21 n = 2 k = 22 n = 3 k = 21 n = 1 k = 22 n = 2 k = 22 n = 1 y = 5

9   Pass
x = '01010101010101010101010101'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

len = 26 x = '01010101010101010101010101' k = 3 n = 1 m = 1 k = 5 n = 1 k = 7 n = 1 k = 9 n = 1 k = 11 n = 1 k = 13 n = 1 k = 15 n = 1 k = 17 n = 1 k = 19 n = 1 k = 21 n = 1 k = 23 n = 1 k = 25 n = 1 k = 27 n = 1 y = 1

10   Pass
x = '0101010111000101110001011100010100001110110100000000110001001000001110001000111010101001101100001111'; y_correct = 4; assert(isequal(lengthOnes(x),y_correct))

len = 100 x = '0101010111000101110001011100010100001110110100000000110001001000001110001000111010101001101100001111' k = 3 n = 1 m = 1 k = 5 n = 1 k = 7 n = 1 k = 9 n = 1 k = 10 n = 2 k = 11 n = 3 m = 3 k = 10 n = 1 k = 11 n = 2 k = 11 n = 1 k = 15 n = 1 k = 17 n = 1 k = 18 n = 2 k = 19 n = 3 k = 18 n = 1 k = 19 n = 2 k = 19 n = 1 k = 23 n = 1 k = 25 n = 1 k = 26 n = 2 k = 27 n = 3 k = 26 n = 1 k = 27 n = 2 k = 27 n = 1 k = 31 n = 1 k = 33 n = 1 k = 38 n = 1 k = 39 n = 2 k = 40 n = 3 k = 39 n = 1 k = 40 n = 2 k = 40 n = 1 k = 42 n = 1 k = 43 n = 2 k = 43 n = 1 k = 45 n = 1 k = 54 n = 1 k = 55 n = 2 k = 55 n = 1 k = 59 n = 1 k = 62 n = 1 k = 68 n = 1 k = 69 n = 2 k = 70 n = 3 k = 69 n = 1 k = 70 n = 2 k = 70 n = 1 k = 74 n = 1 k = 78 n = 1 k = 79 n = 2 k = 80 n = 3 k = 79 n = 1 k = 80 n = 2 k = 80 n = 1 k = 82 n = 1 k = 84 n = 1 k = 86 n = 1 k = 89 n = 1 k = 90 n = 2 k = 90 n = 1 k = 92 n = 1 k = 93 n = 2 k = 93 n = 1 k = 98 n = 1 k = 99 n = 2 k = 100 n = 3 k = 101 n = 4 m = 4 k = 99 n = 1 k = 100 n = 2 k = 101 n = 3 k = 100 n = 1 k = 101 n = 2 k = 101 n = 1 y = 4