Python || Dynamic Programming || Simple Solution
IntuitionApproachComplexity
Time complexity:
O(N * max(nums))
Space complexity:
O(N * max(nums))Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```python3 []
class Solution:
    def longestSubsequence(self, nums: List[int]) -> int:
        m = max(nums)
        check = set()
        dp = [[0 for _ in range(m)] for _ in range(m + 1)]
        ln = len(nums)
        for i in range(ln - 1, -1, -1):
            n = nums[i]
            temp = [1 for _ in range(m)] 
            for j in range(m):
                left, right = n - j, n + j
                if left in check:
                    temp[j] = 1 + dp[left][j]
                if right in check:
                    temp[j] = max(temp[j], 1 + dp[right][j])
            for j in range(1, m):
                temp[j] = max(temp[j], temp[j - 1])
            dp[n] = temp
            check.add(n)
        return max([i[-1] for i in dp])
        
```
['Dynamic Programming', 'Python3']