values. Cross out any number of elements (possibly none), keeping the rest in their original order, so that every remaining element differs from the one before it by the same amount. The gap may be positive, negative or zero.
Return the greatest possible length of such a chain.values=[2, 9, 5, 1, 8, 11] → 4
Pick 2, 5, 8, 11: each neighbour differs by exactly 3. No chain is longer.
values=[10, 7, 10, 4, 10] → 3
Both 10, 10, 10 (gap 0) and 10, 7, 4 (gap -3) work, each of length 3.
values=[5, 1] → 2
Any two numbers form a chain with an equal gap.
values=[2, 9, 5, 1, 8, 11]
4
Run checks the first 3 tests in your browser. Submit checks all 152 tests on the server, hidden ones included.