Cody

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

25.24% Correct | 74.76% Incorrect
Last solution submitted on Jun 09, 2016

Problem Comments

Solution Comments

Tags

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more