class Solution:
def longestSubsequence(self, arr: List[int], difference: int) -> int:
dp = defaultdict(int)
for v in arr:
dp[v] = dp[v - difference] + 1
return max(dp.values())
05-05
2924
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-05
575
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)