Cody

Problem 317. Find the stride of the longest skip sequence

Solution 1900569

Submitted on 15 Aug 2019
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   Fail
a = [1 5 3 11 7 2 4 9]; stride = 2; assert(isequal(skip_sequence_stride(a),stride))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8

Index exceeds the number of array elements (8). Error in skip_sequence_stride (line 6) if a(i)>a(i+1) Error in Test1 (line 3) assert(isequal(skip_sequence_stride(a),stride))

2   Fail
a = [1:5:20 23:3:42 2:9:100]; stride = 9; assert(isequal(skip_sequence_stride(a),stride))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8 m = 9 m = 10 m = 11 m = 12 m = 13 m = 14 m = 15 m = 16 m = 17 m = 18 m = 19 m = 20 m = 21 m = 22

Index exceeds the number of array elements (22). Error in skip_sequence_stride (line 6) if a(i)>a(i+1) Error in Test2 (line 3) assert(isequal(skip_sequence_stride(a),stride))

3   Fail
a = [2:2:22 13:17]; a = a(randperm(length(a))); stride = 2; assert(isequal(skip_sequence_stride(a),stride))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8 m = 9 m = 10 m = 11 m = 12 m = 13 m = 14 m = 15 m = 16

Index exceeds the number of array elements (16). Error in skip_sequence_stride (line 6) if a(i)>a(i+1) Error in Test3 (line 4) assert(isequal(skip_sequence_stride(a),stride))

4   Fail
a = 37:5:120; a = a(randperm(length(a))); stride = 5; assert(isequal(skip_sequence_stride(a),stride))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8 m = 9 m = 10 m = 11 m = 12 m = 13 m = 14 m = 15 m = 16 m = 17

Index exceeds the number of array elements (17). Error in skip_sequence_stride (line 6) if a(i)>a(i+1) Error in Test4 (line 4) assert(isequal(skip_sequence_stride(a),stride))

5   Fail
a = [1:5 101:10:171 201:205]; a = a(randperm(length(a))); stride = 10; assert(isequal(skip_sequence_stride(a),stride))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8 m = 9 m = 10 m = 11 m = 12 m = 13 m = 14 m = 15 m = 16 m = 17 m = 18

Index exceeds the number of array elements (18). Error in skip_sequence_stride (line 6) if a(i)>a(i+1) Error in Test5 (line 4) assert(isequal(skip_sequence_stride(a),stride))

6   Fail
a = [7:17:302 primes(300)]; a = sort(a); stride = 17; assert(isequal(skip_sequence_stride(a),stride))

m = 1 m = 2 m = 3 m = 4 m = 5 m = 6 m = 7 m = 8 m = 9 m = 10 m = 11 m = 12 m = 13 m = 14 m = 15 m = 16 m = 17 m = 18 m = 19 m = 20 m = 21 m = 22 m = 23 m = 24 m = 25 m = 26 m = 27 m = 28 m = 29 m = 30 m = 31 m = 32 m = 33 m = 34 m = 35 m = 36 m = 37 m = 38 m = 39 m = 40 m = 41 m = 42 m = 43 m = 44 m = 45 m = 46 m = 47 m = 48 m = 49 m = 50 m = 51 m = 52 m = 53 m = 54 m = 55 m = 56 m = 57 m = 58 m = 59 m = 60 m = 61 m = 62 m = 63 m = 64 m = 65 m = 66 m = 67 m = 68 m = 69 m = 70 m = 71 m = 72 m = 73 m = 74 m = 75 m = 76 m = 77 m = 78 m = 79 m = 80

Index exceeds the number of array elements (80). Error in skip_sequence_stride (line 6) if a(i)>a(i+1) Error in Test6 (line 4) assert(isequal(skip_sequence_stride(a),stride))