JavaScript solution | DP
Complexity
Time complexity: O(n * n)
Space complexity: O(target)
Code
# Complexity
- Time complexity: O(n * n)
- Space complexity: O(target)

# Code
```javascript []
var lengthOfLongestSubsequence = function(nums, target) {
    let dp = new Array(target + 1).fill(-Infinity);
    dp[0] = 0;

    for(let num of nums) {
        for(let j = target; j>= num; j--) {
            dp[j] = Math.max(dp[j], dp[j - num] + 1);
        }
    }
    return dp[target] == -Infinity ? -1 : dp[target];
};
```
['Array', 'Dynamic Programming', 'JavaScript']