Cody

Problem 672. Longest run of consecutive numbers

Solution 2867969

Submitted on 22 Aug 2020 by Hawt Strokes
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))

r = 1 c = 11 isTranspose = logical 0 counterMat = 1 1 columnIndex = 1 columnIndex = 2 counterMat = 1 2 1 1 counterMat = 1 2 1 2 counterMat = 1 2 1 3 columnIndex = 3 counterMat = 1 2 1 1 3 1 columnIndex = 4 counterMat = 1 2 1 3 1 3 1 1 columnIndex = 5 counterMat = 1 2 1 3 2 1 3 1 1 1 columnIndex = 6 counterMat = 1 2 1 3 2 1 1 3 1 1 1 1 columnIndex = 7 counterMat = 1 2 1 3 2 1 4 1 3 1 1 1 1 1 columnIndex = 8 counterMat = 1 2 1 3 2 1 4 5 1 3 1 1 1 1 1 1 columnIndex = 9 counterMat = 1 2 1 3 2 1 4 5 1 1 3 1 1 1 1 1 1 1 maxCount = 3 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))

r = 1 c = 9 isTranspose = logical 0 counterMat = 1 1 columnIndex = 1 counterMat = 1 2 counterMat = 1 3 columnIndex = 2 counterMat = 1 2 3 1 counterMat = 1 2 3 2 counterMat = 1 2 3 3 columnIndex = 3 counterMat = 1 2 3 3 3 1 counterMat = 1 2 3 3 3 2 counterMat = 1 2 3 3 3 3 maxCount = 3 val = 1 2 3

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

r = 1 c = 7 isTranspose = logical 0 counterMat = -2 1 columnIndex = 1 counterMat = -2 2 counterMat = -2 3 counterMat = -2 4 columnIndex = 2 counterMat = -2 -1 4 1 columnIndex = 3 counterMat = -2 -1 0 4 1 1 columnIndex = 4 counterMat = -2 -1 0 3 4 1 1 1 maxCount = 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))

r = 1 c = 12 isTranspose = logical 0 counterMat = 0 1 columnIndex = 1 columnIndex = 2 counterMat = 0 1 1 1 counterMat = 0 1 1 2 counterMat = 0 1 1 3 columnIndex = 3 counterMat = 0 1 0 1 3 1 columnIndex = 4 counterMat = 0 1 0 2 1 3 1 1 counterMat = 0 1 0 2 1 3 1 2 columnIndex = 5 counterMat = 0 1 0 2 0 1 3 1 2 1 columnIndex = 6 counterMat = 0 1 0 2 0 1 1 3 1 2 1 1 counterMat = 0 1 0 2 0 1 1 3 1 2 1 2 counterMat = 0 1 0 2 0 1 1 3 1 2 1 3 columnIndex = 7 counterMat = 0 1 0 2 0 1 0 1 3 1 2 1 3 1 maxCount = 3 val = 1 1

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

r = 7 c = 1 isTranspose = logical 1 counterMat = 3 1 columnIndex = 1 counterMat = 3 2 counterMat = 3 3 columnIndex = 2 counterMat = 3 2 3 1 counterMat = 3 2 3 2 columnIndex = 3 counterMat = 3 2 1 3 2 1 columnIndex = 4 counterMat = 3 2 1 6 3 2 1 1 maxCount = 3 val = 3

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

r = 8 c = 1 isTranspose = logical 1 counterMat = 3 1 columnIndex = 1 counterMat = 3 2 counterMat = 3 3 columnIndex = 2 counterMat = 3 2 3 1 counterMat = 3 2 3 2 counterMat = 3 2 3 3 columnIndex = 3 counterMat = 3 2 1 3 3 1 columnIndex = 4 counterMat = 3 2 1 6 3 3 1 1 maxCount = 3 val = 3 2

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

r = 5 c = 1 isTranspose = logical 1 counterMat = 1 1 columnIndex = 1 columnIndex = 2 counterMat = 1 2 1 1 columnIndex = 3 counterMat = 1 2 3 1 1 1 columnIndex = 4 counterMat = 1 2 3 4 1 1 1 1 columnIndex = 5 counterMat = 1 2 3 4 5 1 1 1 1 1 maxCount = 1 val = 1 2 3 4 5

Suggested Problems

More from this Author80

Community Treasure Hunt

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

Start Hunting!