Simple Dynamic Programming Approach
IntuitionSince the range of values is small we can store information about longest subsequences starting from specific values and having differences less than o
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Since the range of values is small we can store information about longest subsequences starting from specific values and having differences less than or equal to some value.

# Approach
<!-- Describe your approach to solving the problem. -->
Going from back to front, compute for the current number $num$ and for each possible absolute difference $d$, the maximum length subsequence starting from that number and having differences less than or equal to $d$ between successive elements.

To do so, we can use information computed earlier. For each other number $num2$, update $dp[num][abs(num - num2)]$ using $dp[num2][abs(num - num2)]$.

Once this is done we can compute $dp[num][diff]$ as $max_{d \leq diff}dp[num][d]$. This is done because we are interested in the longest subsequences whose differences between successive elements are bounded by $diff$.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$O(n*max\_value)$

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$O(max\_value^2)$
# Code
```cpp []
class Solution {
public:
    int longestSubsequence(vector<int>& nums) {
        vector<vector<int>> dp(302, vector<int>(302));

        for (int i = nums.size() - 1; i >= 0; --i){
            int num = nums[i];
    
            for (int next = 1; next <= 300; ++next){
                int diff = abs(next - num);
                dp[num][diff] = max(dp[num][diff], dp[next][diff] + 1);
            }

            for (int j = 1; j <= 300; ++j){
                dp[num][j] = max(dp[num][j], dp[num][j - 1]);
            }
        }

        int ans = INT_MIN;
        for (int i = 0; i <= 301; ++i){
            for (int j = 0; j <= 301; ++j){
                ans = max(ans, dp[i][j]);
            }
        }

        return ans;
    }
};
```
['Dynamic Programming', 'C++']