Longest arithmetic subsequence

Write codeMedium25 min

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) -> int
Example 1
Inputlongest_arith_subseq([1, 2, 3, 4], 1)
Output4