Javascript - DP
Code
# Code
```javascript []
/**
 * @param {number[]} nums
 * @return {number}
 */
var longestSubsequence = function (nums) {
  let ans = 0;
  const dp = new Array(301).fill().map(() => new Array(301).fill(0));

  for (let i = nums.length - 1; i >= 0; i--) {
    const num = nums[i];
    for (let next = 1; next <= 300; next++) {
      const diff = Math.abs(num - next);
      dp[num][diff] = Math.max(dp[num][diff], dp[next][diff] + 1);
    }
    for (let diff = 1; diff <= 300; diff++) {
      dp[num][diff] = Math.max(dp[num][diff], dp[num][diff - 1]);
      ans = Math.max(ans, dp[num][diff]);
    }
  }

  return ans;
};
  
```
['Dynamic Programming', 'JavaScript']