(Beats 100% runtime)Python Solution. Concise and easily understandable.
IntuitionTo understand this problem, let us imagine that we have already picked a few numbers(forming a valid subsequence) and currently we are picking number n
# Intuition
To understand this problem, let us imagine that we have already picked a few numbers(forming a valid subsequence) and currently we are picking number **num** from middle of the array(while going from left to right).
This number has a difference of **diff** from the previous element we picked.

----
This means that the previous number we picked was either num-diff or num+diff for the subsequence to be valid.
Therefore prev = num-diff or num+diff.

---

All the  differences before the current **diff** (i.e. abs(prev-num))in this valid subsequence should either be greater than or equal to **diff**.

Imagine we are storing that value in a dictionary dp[prev][diff].
What this value actually stores is: 

#### Equation :
```
dp[prev][diff] = max(dp[prev][diff], dp[prev][diff+1], dp[prev][diff+2]+.....+dp[prev][n]).                                     
```

This represents maximum subsequence length formed(at element prev) so far where the next difference required is **diff**.

### Why are we storing maxValue from range (diff -> 300)?
Because the current difference from previous element **prev** is  **diff**, so the difference of **prev** element from its previous element is allowed to be >diff up to 300. And picking max would give us the longest subsequence.

Eg. 100,15,10 is a valid sequence.
In this the latest difference is 15-10=5, but the difference before that is 100-15 = 75. If the subsequence was 9,15,10, even then it would have been valid. The first number in this sequence could have been anything in range [1-10](diff >=5) and [20-300](diff >=5). We pick max to calculate  longest subsequence.


# Approach
Given that the numbers are only in range 1-300, we can see that the differences will also be in the range(0,299). 0 in case there are same numbers at 2 different indexes.

1) For loop to pick elements from left to right. Time: O(n)
In the ith iteration of for loop we are assuming that we are definitely picking the ith element and calculating the maximum subsequence we can obtain so far.
2) The nested for loop is in decreasing order from 300 to 0 to account for 
equation mentioned above. Time: O(300)

Check for max sequence we have obtained so far and return result.


# Complexity
- Time complexity: O(300*n)


- Space complexity: O(300*n)

# Code
```python3 []
class Solution:
    def longestSubsequence(self, nums: List[int]) -> int:
        n = len(nums)
        dp ={}
        maxSoFar = 0
        for i in range(n):
            number = nums[i]
            maxSub = 1
            for diff in range(300,-1,-1):
                number1 = number-diff
                number2 = number+diff
                if(number1, diff) in dp:
                    maxSub = max(maxSub, dp[(number1, diff)]+1)
                if(number2, diff) in dp:
                    maxSub = max(maxSub, dp[(number2, diff)]+1)
                dp[(number, diff)] = maxSub
                maxSoFar = max(maxSoFar, maxSub)
        return maxSoFar
            
            
                

            
    
```
['Python3']