2d DP
Intuitionlots of optimization needed to solve this problem. as you can see in comments naive DP is too slow because it takes n^2 worse case. take advantage of o
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
lots of optimization needed to solve this problem. as you can see in comments naive DP is too slow because it takes n^2 worse case. take advantage of only values between 0 and 300. 

# Approach
<!-- Describe your approach to solving the problem. -->
In one pass, you can check every combination of diff/num. Since you only need to consider `i + diff` and `i - diff`. 

# Complexity
- Time complexity: o(nm)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: 
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []

class Solution:
    def longestSubsequence(self, nums: List[int]) -> int:
        n = len(nums)
        m = 301
        dp = {} # number, difference

        for idx, i in enumerate(nums):
            best = 1
            for diff in range(m - 1, -1, -1):
                if i + diff < m:
                    if (i + diff, diff) in dp:
                        best = max(best, dp[(i + diff, diff)] + 1)

                if i - diff >= 0 :
                    if (i - diff, diff) in dp:
                        best = max(best, dp[(i - diff, diff)] + 1)

                dp[(i, diff)] = best
        return max(dp.values())
```
['Python3']