Problem 317. Find the stride of the longest skip sequence
We define a skip sequence as a regularly-spaced list of integers such as might be generated by MATLAB's colon operator. We will call the inter-element increment the stride. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.
Given the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.
Example:
input a = [1 5 3 11 7 2 4 9] output stride is 2
since from the elements of a we can build the six-element sequence [1 3 5 7 9 11].
Solution Stats
Problem Comments
-
4 Comments
Fair enough. I changed the wording to remove the ambiguity.
I added another test and rescored. It appears that DIST no longer works. The DIST function is from the Neural Networks Toolbox. It shouldn't have worked in the past, but since it did, it played a part in a lot of answers. Sorry for the discontinuity.
Tough !
Two years before understand that the sequence must contain only elements of a :)
Solution Comments
Show commentsGroup

Sequences & Series I
- 14 Problems
- 87 Finishers
- Sum all integers from 1 to 2^n
- Integer sequence - 2 : Kolakoski sequence
- Sum all integers from 1 to 2^n
- Project Euler: Problem 2, Sum of even Fibonacci
- Sum of first n terms of a harmonic progression
- Project Euler: Problem 6, Natural numbers, squares and sums.
- Integer Sequence - II : New Fibonacci
- Project Euler: Problem 2, Sum of even Fibonacci
- Project Euler: Problem 6, Natural numbers, squares and sums.
- Find the stride of the longest skip sequence
- Sum the Infinite Series
- Return the Fibonacci Sequence
- Sum of first n terms of a harmonic progression
- "Look and say" sequence
- Is X a Fibonacci Matrix?
- Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
- Golomb's self-describing sequence (based on Euler 341)
- Alternating sum
- Integer sequence - 2 : Kolakoski sequence
- Integer Sequence - II : New Fibonacci
Problem Recent Solvers162
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!