 Longest Subsequence With Decreasing Adjacent Difference
IntuitionApproachDynamic ProgrammingComplexity
Time complexity:O(N*300)

Space complexity:O(301*301)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
Dynamic Programming 
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:O(N*300)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(301*301)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int longestSubsequence(int[] nums) {
      int res=0;
      int dp[][]=new int[301][301];
      for(int i=nums.length-1;i>=0;--i){
        for(int num=1;num<=300;++num){
            int diff=Math.abs(nums[i]-num);
            dp[nums[i]][diff]=Math.max(dp[nums[i]][diff],dp[num][diff]+1);
        }
        for(int diff=1;diff<300;++diff){
            dp[nums[i]][diff]=Math.max(dp[nums[i]][diff],dp[nums[i]][diff-1]);
            res=Math.max(res,dp[nums[i]][diff]);
        }
      }
      return res;
    }
}
```
['Java']