Cody

# Problem 42894. Find longest run

Solution 919417

Submitted on 6 Jul 2016 by Zikobrelli
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
binary_array = [1 1 0 1]; expected_length = 2; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

B_1 = 0 1 1 0 1 0 C_1 = 1 4 run_length_1 = 2 start_index_1 = 1 B_0 = 0 0 0 1 0 0 C_0 = 3 run_length_0 = 1 start_index_0 = 3 run_length = 2 start_index = 1

2   Pass
binary_array = [1 1 0 1 0 0 0 0 1 1 1]; expected_length = 4; expected_index = 5; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

B_1 = 0 1 1 0 1 0 0 0 0 1 1 1 0 C_1 = 1 4 9 run_length_1 = 3 start_index_1 = 9 B_0 = 0 0 0 1 0 1 1 1 1 0 0 0 0 C_0 = 3 5 run_length_0 = 4 start_index_0 = 5 run_length = 4 start_index = 5

3   Pass
binary_array = [1 0]; expected_length = 1; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

B_1 = 0 1 0 0 C_1 = 1 run_length_1 = 1 start_index_1 = 1 B_0 = 0 0 1 0 C_0 = 2 run_length_0 = 1 start_index_0 = 2 run_length = 1 start_index = 1

4   Pass
binary_array = ; expected_length = 1; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

B_1 = 0 1 0 C_1 = 1 run_length_1 = 1 start_index_1 = 1 B_0 = 0 0 0 C_0 = Empty matrix: 1-by-0 run_length_0 = Empty matrix: 1-by-0 start_index_0 = Empty matrix: 1-by-0 run_length = 1 start_index = 1

5   Pass
binary_array = [1 1 1 1 1 1]; expected_length = 6; expected_index = 1; [actual_length actual_index] = longest_run(binary_array); assert(isequal(expected_length, actual_length)); assert(isequal(expected_index, actual_index));

B_1 = 0 1 1 1 1 1 1 0 C_1 = 1 run_length_1 = 6 start_index_1 = 1 B_0 = 0 0 0 0 0 0 0 0 C_0 = Empty matrix: 1-by-0 run_length_0 = Empty matrix: 1-by-0 start_index_0 = Empty matrix: 1-by-0 run_length = 6 start_index = 1