readings. Call a stretch of the array (a run of consecutive elements) even if it has at least three elements and the difference between every two neighbours is the same.
For example, [1, 4, 7, 10], [6, 6, 6] and [9, 5, 1] are even stretches, while [1, 2, 4] is not.
Return how many even stretches readings contains. Stretches with a different start or end count separately.readings=[2, 4, 6, 8] → 3
[2, 4, 6], [4, 6, 8] and the whole array [2, 4, 6, 8] all qualify, each with a step of 2.
readings=[5, 5, 5, 1, -3] → 2
[5, 5, 5] with step 0 and [5, 1, -3] with step -4. [5, 5, 1] does not count, since its steps 0 and -4 differ.
readings=[7, 3] → 0
There is no stretch of length 3 or more.
readings=[2, 4, 6, 8]
3
Run checks the first 3 tests in your browser. Submit checks all 173 tests on the server, hidden ones included.