Easy understanding python solution 100% beats solution
Complexity
Time complexity: O(n)

Space complexity: O(n)
Code
![image.png](https://assets.leetcode.com/users/images/12cf41c9-713c-4dc4-9e66-a9b42f8564b3_1736065532.7006729.png)


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

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

# Code
```python3 []
class Solution:
    def longestSubsequence(self, nums: List[int]) -> int:
        dp = [[0]*301 for _ in range(301)]
        suffix_max = [[0]*301 for _ in range(301)]
        ans = 1

        for num in nums:
            if(dp[num][0] < 1): dp[num][0] = 1
            for prev in range(1,301):
                dnew = abs(prev-num)
                bestChain = suffix_max[prev][dnew]
                if(bestChain > 0):
                    dp[num][dnew] = max(dp[num][dnew],1+bestChain)
                else:
                    if suffix_max[prev][0] > 0:
                        dp[num][dnew] = max(dp[num][dnew],2)
                ans = max(ans,dp[num][dnew])
            
            suffix_max[num][299] = dp[num][299]
            for i in range(298,-1,-1):
                suffix_max[num][i] = max(suffix_max[num][i+1],dp[num][i])
        return ans
                

        

```
['Dynamic Programming', 'Greedy', 'Python3']