Longest arithmetic subsequence
Your task
Given an integer array and an integer difference d, return the length of the longest subsequence (elements in original order, not necessarily contiguous) that forms an arithmetic sequence with common difference exactly d. The array has at most 100000 elements with values in [-10000, 10000].
Examples
longest_arith_subseq(arr: list[int], d: int) -> intExample 1
Input
longest_arith_subseq([1, 2, 3, 4], 1)Output
4