Javascript - DP
Code\n\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar lengthOfLongestSubsequence = function (nums, target) {\n  const
# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar lengthOfLongestSubsequence = function (nums, target) {\n  const n = nums.length;\n  const dp = new Array(n + 1)\n    .fill()\n    .map((_) => new Array(target + 1).fill(-Infinity));\n\n  for (let i = 0; i <= n; i++) dp[i][0] = 0;\n\n  for (let i = 0; i < n; i++) {\n    const currNum = nums[i];\n    for (let currTarget = 1; currTarget <= target; currTarget++) {\n      dp[i + 1][currTarget] = dp[i][currTarget];\n\n      if (currTarget >= currNum) {\n        dp[i + 1][currTarget] = Math.max(\n          dp[i + 1][currTarget],\n          dp[i][currTarget - currNum] + 1\n        );\n      }\n    }\n  }\n\n  return dp[n][target] === -Infinity ? -1 : dp[n][target];\n};\n\n```
['Dynamic Programming', 'JavaScript']