Best, simple dp (intuition + solution), O(N) !
IntuitionThe problem involves finding the longest subsequence in an array such that the absolute difference between adjacent elements is constant. By maintainin
# Intuition
The problem involves finding the longest subsequence in an array such that the absolute difference between adjacent elements is constant. By maintaining a dp table and optimizing it with a suffixMax array, we can efficiently compute the result.

# Approach
Dynamic Programming State:
dp[num][diff]: Represents the maximum length of a subsequence ending with num and having a difference diff.

Suffix Maximum Array:
suffixMax[num][diff]: The maximum length of a subsequence ending with num for all differences >= diff.
This helps in efficiently computing the maximum subsequence length when the exact difference isn't fixed but is bounded.

Logic:
Iterate through each number num in nums.
Update dp[num][diff] by considering every prev value (potential previous number in the subsequence) and calculating the difference diff = |num - prev|.
Use suffixMax[prev][diff] to fetch the best subsequence length ending with prev for the current difference and update dp[num][diff].
Update the global answer ans after every computation.

Suffix Array Update:
After processing all potential prev values for num, update suffixMax[num] for all differences from 299 down to 0. This ensures the array always has the best possible subsequence lengths for any >= diff.

# Complexity
- Time complexity:
O(n*301 + n*301) === O(n)

- Space complexity:
O(301 * 301) === O(1)

# Code
```java []
class Solution {
    public int longestSubsequence(int[] nums) {
        int n=nums.length;
        int[][] dp=new int[301][301]; //dp[i][j] gives max len with cur val=i and curdiff=j
        int[][] suffixMax=new int[301][301]; //gives max len of subseq ending with prevnum i and a diff i.e. >= curdiff
        
        int ans=1;
        for(int num: nums){
            if(dp[num][0]<1) dp[num][0]=1;

            for(int prev=0; prev<=300; prev++){
                int curdiff=Math.abs(num-prev);
                int curbestlen=suffixMax[prev][curdiff];

                if(curbestlen>0){
                    dp[num][curdiff]=Math.max(1+curbestlen, dp[num][curdiff]);
                }
                else{
                    if(suffixMax[prev][0]>0){
                        dp[num][curdiff]=Math.max(dp[num][curdiff], 2);
                    }
                }
                ans=Math.max(ans, dp[num][curdiff]);
            }

            suffixMax[num][299]=dp[num][299];
            for(int d=298; d>=0; d--){
                suffixMax[num][d]=Math.max(dp[num][d], suffixMax[num][d+1]);
            }
        }
        return ans;
    }
}
```
['Java']