My Solution
```
/**
 * Time Complexity: O(n * num_range)
 * Space Complexity: O(num_range * num_range)
 * where `n` is the length of the vector `nums`
 *       `num_range` is (`max_num` - `min_num` + 1)
 *       `max_num` is the maximum element of the vector `nums`
 *       `min_num` is the minimum element of the vector `nums`
 */
class Solution {
 public:
  int longestSubsequence(const vector<int> &nums) {
    const int n = static_cast<int>(nums.size());
    const auto mm = minmax_element(nums.begin(), nums.end());
    const int min_num = *mm.first;
    const int max_num = *mm.second;
    const int num_range = max_num - min_num + 1;
    /**
     * assume that,
     * 1. the current index of the vector `nums` is `i`,
     *    so the current element is `nums[i]`
     * 2. `min_num` is the minimum element of the vector `nums`
     *
     * dp[num][d] stands for the length of the longest subsequence,
     * the absolute difference of whose last two elements is equal to or greater than `d`,
     * of the subarray,
     * which starts from `nums[0]` and ends with the current element, that is, `nums[i]`,
     * where `num` is the value (`nums[j]` - `min_num`),
     *       `j` is in the range [`0`, `i`], both inclusive
     */
    int dp[num_range][num_range];
    memset(dp, 0, sizeof(dp));
    int ret = 0;
    for (int i = 0; i < n; ++i) {
      const int num = nums[i] - min_num;
      for (int d = num_range - 1; d > -1; --d) {
        const int previous_num = num - d;
        const int next_num = num + d;
        dp[num][d] = max({
          /**
           * option 1: the subsequence only contains the current element `nums[i]`,
           *           so the length is `1`
           */
          1,
          /**
           * option 2: the length of the subsequence which ends with the current element,
           *           and the absolute difference between whose last two elements
           *           is equal to or greater than (`d` + 1)
           */
          d == num_range - 1 ? 0 : dp[num][d + 1],
          /**
           * option 3: `dp[num - d][d]` if (`num` - `d`) is valid
           */
          previous_num > -1 && previous_num < num_range ? dp[previous_num][d] + 1 : 0,
          /**
           * option 4: `dp[num + d][d]` if (`num` + `d`) is valid
           */
          next_num > -1 && next_num < num_range ? dp[next_num][d] + 1 : 0
        });
        ret = max(ret, dp[num][d]);
      }
    }
    return ret;
  }
};
```
['C++']