Easy to Understand Simple Approach (C++)
Intuition2-D DP Problem
Store DP[last_element][abs(diff)] = lengthApproachCreate a DP array of size 301*301.
For all numbers in array take last from 0 to 301 an
# Intuition
2-D DP Problem 
Store DP[last_element][abs(diff)] = length
# Approach
Create a DP array of size 301*301.
For all numbers in array take last from 0 to 301 and update length after calculating abs(diff) between cur and last element as max(dp[last_ele][diff]+1) if it is more than DP[cur_ele][diff].
Now any diff for nums[i] can also use diff+1 or more. So update diff for nums[i] as max(cur,next) for all diff from 0 to 300.
At last take the maximum element in the DP array. 
- **CONGRATS, YOUR SOLUTION IS ACCEPTED!!!**
- ***PLEASE UPVOTE!!!***

# Complexity
- Time complexity: $$O(n*max(nums))$$

- Space complexity: $$O(max(nums)^2)$$

# Code
```cpp []
class Solution {
public:
    int longestSubsequence(vector<int>& nums) {
        int n = nums.size();
        vector<vector<int>> dp(301,vector<int> (301,0));
        for(int i=0; i<n; i++)
            {
                for(int j=0; j<=300; j++)
                    {
                        int x = abs(nums[i]-j);
                        dp[nums[i]][x] = max(dp[nums[i]][x], dp[j][x]+1);
                    }
                for(int j=299; j>=0; j--)
                    {
                        dp[nums[i]][j] = max(dp[nums[i]][j], dp[nums[i]][j+1]);
                    }
            }
        int ans = 0;
        for(int i=0; i<=300; i++)
            {
                for(int j=0; j<=300; j++)
                    ans = max(ans,dp[i][j]);
            }
        return ans;
    }
};
```
['Dynamic Programming', 'C++']