python 2d DP w/ prefix(suffix) max
In dp we store for each pair (num, diff) the max length of a sequence ending at num with the smallest diff being at least diff. We do this by iterating over eac
In dp we store for each pair (num, diff) the max length of a sequence ending at num with the smallest diff being at least diff. We do this by iterating over each num in nums and check for each difference, diff, if num+diff and num-diff are in the range and if they are we check if we have seen one of them before by checking if (num+diff, diff) in dp (likewise for num-diff). We check (num+diff, diff) because this ensures that the difference for a sequence ending at num+diff is at least diff which is the current diff we are on (thus constructing a valid sequence). We update the max value for each diff going down from 300 (keeping track of the max length of a sequence ending at the num with a difference at least diff). 

Basically dp[(num, d)] = max(dp[(num, d)] for d in range(d+1, 301))

# Code
```python3 []
class Solution:
    def longestSubsequence(self, nums: List[int]) -> int:
        n = len(nums)
        dp = {} #(no, diff) - length for that pair

        for x in nums:
            m = 1

            for d in range(300, -1, -1):

                # x will be there if d+x is there
                if d+x <= 300 and (d+x,d) in dp:
                    m = max(m, 1+dp[(d+x, d)])
                
                if x-d >= 0 and (x-d, d) in dp:
                    m = max(m, 1+dp[(x-d, d)])
                
                # by doing this we don't need to iterate over all values of x in the future
                # we've accounted for all differences >= d, so we store the max length for all
                # sequences ending at x with length >= d
                dp[(x, d)] = m
        
        return max(dp.values())
```
['Python3']