Problem statement

https://binarysearch.com/problems/Steady-Speed/

Solution

Evaluate absolute difference of adjacent elements, then use groupby.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, P):
        diff = [abs(x - y) for x, y in zip(P, P[1:])]
        return max(len(list(j)) + 1 for i, j in groupby(diff))