[
math
dp
]
BinarySearch 0459 Arithmetic Sequences
Problem statement
https://binarysearch.com/problems/Arithmetic-Sequences/
Solution
Equal to Leetcode 0413. Arithmetic Slices.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, A):
B = [j-i for i,j in zip(A, A[1:])]
return sum(((2*len(list(j))-1)**2-1)//8 for i, j in groupby(B))