Cody

# Problem 672. Longest run of consecutive numbers

Solution 1943193

Submitted on 19 Sep 2019 by Augusto Mazzei
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 2 2 2 1 3 2 1 4 5 1]; y_correct = 2; assert(isequal(longrun(a),y_correct))

v = 10 9 8 7 6 5 4 3 2 1 x = 1×10 cell array {[2]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} matches = 1×10 logical array 0 0 0 0 0 0 0 0 1 1 idx = 9 val = 2

2   Pass
a = [1 1 1 2 2 2 3 3 3]; y_correct = [1 2 3]; assert(isequal(longrun(a),y_correct))

v = 8 7 6 5 4 3 2 1 x = 1×8 cell array {[6]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} matches = 1×8 logical array 0 0 0 0 0 0 1 1 idx = 7 val = 1 2 3

3   Pass
a = [-2 -2 -2 -2 -1 0 3]; y_correct = -2; assert(isequal(longrun(a),y_correct))

v = 6 5 4 3 2 1 x = 1×6 cell array {[3]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} matches = 1×6 logical array 0 0 0 1 1 1 idx = 4 val = -2

4   Pass
a=[0 1 1 1 0 2 2 0 1 1 1 0]; y_correct = [1 1]; assert(isequal(longrun(a),y_correct))

v = 11 10 9 8 7 6 5 4 3 2 1 x = 1×11 cell array {[5]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} matches = 1×11 logical array 0 0 0 0 0 0 0 0 0 1 1 idx = 10 val = 1 1

5   Pass
a=[3 3 3 2 2 1 6]'; y_correct=3; assert(isequal(longrun(a),y_correct))

v = 6 5 4 3 2 1 x = 1×6 cell array {[3]} {2×1 double} {3×1 double} {4×1 double} {5×1 double} {6×1 double} matches = 1×6 logical array 0 0 0 0 1 1 idx = 5 val = 3

6   Pass
a=[3 3 3 2 2 2 1 6]'; y_correct=[3 2]'; assert(isequal(longrun(a),y_correct))

v = 7 6 5 4 3 2 1 x = 1×7 cell array {[4]} {2×1 double} {3×1 double} {4×1 double} {5×1 double} {6×1 double} {7×1 double} matches = 1×7 logical array 0 0 0 0 0 1 1 idx = 6 val = 3 2

7   Pass
a=[1 2 3 4 5]'; y_correct=a; assert(isequal(longrun(a),y_correct))

v = 4 3 2 1 x = 1×4 cell array {[0]} {2×1 double} {3×1 double} {4×1 double} matches = 1×4 logical array 0 0 0 0 idx = 1×0 empty double row vector val = 1 2 3 4 5