Similar to Coin Change Pattern | Javascript | DP approach
Code\n\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar lengthOfLongestSubsequence = function (nums, target) {\n    con
# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar lengthOfLongestSubsequence = function (nums, target) {\n    const dp = Array(target + 1).fill(-Infinity)\n    dp[0] = 0\n    for (const n of nums) {\n        for (let i = target; i >= n; i--) {\n            if (n <= i) {\n                dp[i] = Math.max(dp[i], 1 + dp[i - n])\n            }\n        }\n    }\n    if (dp[target] === -Infinity) return -1\n    return dp[target]\n};\n```
['JavaScript']