Javascript DP w/Grid in Comments
Intuition\nDynamic programming approach. \n\n# Notes\nI don\'t typically share answers but I was proud of the grid I made (in the bottom comments) in order to g
# Intuition\nDynamic programming approach. \n\n# Notes\nI don\'t typically share answers but I was proud of the grid I made (in the bottom comments) in order to go through the problem. Maybe it will help out the next person. \n\nIncluded comments throughout. \n\n# Complexity\n- Time complexity:\nO(n * m)\nn = length of nums\nm = target\n\n# Code\n```javascript []\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar lengthOfLongestSubsequence = function(nums, target) {\n    // Create a grid to hold the max amount of subsequences for all numbers from 0 to target\n    let dp = new Array(nums.length +1);\n    // Intialize the grid with all -1 and then fill the first column with 1s. The first column having 1s is the base case. \n    for(let i = 0; i < nums.length+1; i++) {\n        dp[i] = new Array(target +1).fill(-1);\n        dp[i][0] = 0\n    }\n    \n    // Build out the grid based on the below logic. \n    for(let i = 1; i < nums.length +1; i++) { // start at row 1\n        for(let j = 1; j < target +1; j++) { // start at column 1\n\n            // j is the index that is represents the number from 0 to target. \n            // j is considered the current target for the subproblem we are solving.\n            // get the diff between j and the current num.\n            let v = j - nums[i - 1]; // remember to minus 1 from i because this i is 1 index ahead of the number we want from nums\n\n            // Intialize a placeholder value\n            let value = -1;\n            // Check if the diff between j and the current num is greater than or equal to zero;\n            // if so that means the number could be a part of a subsequence to make up this current target (j)\n            if(v >= 0) {\n\n                // We must check if the diff between j and the current number(v) has a solved subsequence indicated by a number besides -1 being in that spot of the grid.\n                // note: you have to do [i-1][v] for the spot  because we want to know if the number(s) before the current number had a subsequence for v.\n                if(dp[i-1][v] !== -1) {\n                    value = dp[i-1][v] + 1\n                }\n            }\n            //Now compare the current subsequnce with the one above to see if the one above is better. \n            dp[i][j] = Math.max(value, dp[i-1][j])\n        }\n    }\n\n    // Return the final node in the grid as it will hold the solution \n    return dp[nums.length][target];\n};\n\n\n/**\nUse the grid below to help yourself walk through the code. \nthe dashes i.e. "-" stand for -1. \n\n      j \n    0 1 2 3 4 5 6 7 8 9\n 0. 0 - - - - - - - - -\ni1  0 - - - - - - - - -\n 2. 0 - - - - - - - - -\n 3. 0 - - - - - - - - -\n 4  0 - - - - - - - - -\n 5  0 - - - - - - - - -\n\n */\n```
['Dynamic Programming', 'JavaScript']