1 class Solution: 2 def longestSubsequence(self, arr: List[int], difference: int) -> int: 3 dp = collections.defaultdict(int) 4 result = 0 5 for val in arr: 6 dp[val] = dp[val-difference] + 1 7 if dp[val] > result: 8 result = dp[val] 9 return result
1 class Solution: 2 def longestSubsequence(self, arr: List[int], difference: int) -> int: 3 dp = collections.defaultdict(int) 4 result = 0 5 for val in arr: 6 dp[val] = dp[val-difference] + 1 7 if dp[val] > result: 8 result = dp[val] 9 return result