Slightly optimized Pythonk solution (~3200ms)
ApproachIterate backwards while keeping track of maximum lengths of subsequences starting with a certain number and having a maximum absolute difference between
# Approach
Iterate backwards while keeping track of maximum lengths of subsequences starting with a certain number and having a maximum absolute difference between two consecutive elements. This ends up being acceptably fast because we know all the values in `nums` are small (we only need 301x301 array in the worst case, and we only need to update one row at each step).

# Code
```python3 []
class Solution:
    def longestSubsequence(self, nums: List[int]) -> int:
        MIN_VALUE = min(nums)
        MAX_VALUE = max(nums)
        MAX_DIFF = MAX_VALUE - MIN_VALUE
        # seqlen[start][maxdiff] is length of longest subsequence that starts with
        # `start` and in which the maximum absolute difference between two
        # consecutive elements is `maxdiff`
        seqlen = [[0 for _ in range(MAX_DIFF + 1)] for _ in range(MAX_VALUE + 1)]

        # iterate BACKWARDS and keep updating seqlen
        for start in reversed(nums):
            lo = max(MIN_VALUE, start - MAX_DIFF)
            hi = min(MAX_VALUE, start + MAX_DIFF)

            # update seqlen to include subsequences starting with current start
            for next_ in range(lo, start):
                diff = start - next_
                if seqlen[next_][diff] >= seqlen[start][diff]:
                    seqlen[start][diff] = seqlen[next_][diff] + 1
            for next_ in range(start, hi + 1):
                diff = next_ - start
                if seqlen[next_][diff] >= seqlen[start][diff]:
                    seqlen[start][diff] = seqlen[next_][diff] + 1

            # prefix maximize seqlen[start] (`scanl1 max` in Haskell)
            max_so_far = seqlen[start][0]
            for diff in range(1, MAX_DIFF + 1):
                if seqlen[start][diff] > max_so_far:
                    max_so_far = seqlen[start][diff]
                else:
                    seqlen[start][diff] = max_so_far

        return max(seqlen[start][MAX_DIFF] for start in range(MIN_VALUE, MAX_VALUE+1))

```

# Python tips

* `reversed(nums)` makes a reverse iterator without creating a copy of the list which saves on memory usage (`nums[::-1]` would allocate a new list).
* Because function calls have relatively high overhead in Python, it's faster to use comparison and assignment instead of calling `min()` and `max()` in hot loops. If you switch to using `max()` in the inner for loops the runtime jumps up to about 7000ms.


# Complexity
Assuming $N$ is the length of `nums`, and $K$ is the maximum value in `nums` (according to given constraints $K <= 300$):
- Time complexity: $O(N*K)$
- Space complexity: $O(K^2)$
['Python3']