Easy understandable solution 
IntuitionApproachComplexity
Time complexity:

Space complexity:
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)$$ -->

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

# Code
```cpp []
class Solution {
public:
    int longestSubsequence(vector<int>& nums) {
        vector<vector<int>> dp(302, vector<int>(302, 0));
        unordered_set<int> present(nums.begin(), nums.end());

        for (int i = nums.size() - 1; i >= 0; i--) {
            int num = nums[i];
            for (int next : present) {
                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', 'Greedy', 'C++']