Classic dp solution. Beats 100%. 114 ms
Intuition\nInitially, I thought that we need to use as many numbers as possible to get the coveted target number. \nThat\'s how it turned out.\n\n# Approach\nTr
# Intuition\nInitially, I thought that we need to use as many numbers as possible to get the coveted target number. \nThat\'s how it turned out.\n\n# Approach\nTry to take the largest number of elements without exceeding the target.\n\n# Complexity\n- Time complexity:O(N*target)\n\n- Space complexity:O(target)\n\n# Code\n```\npublic class Solution {\n    public int LengthOfLongestSubsequence(IList<int> nums, int target) {\n        int[]dp=new int[target+1];\n        Array.Fill(dp,-1);\n        \n        //setupping our dp array and starting from first element\n        \n        dp[0]=0;\n        int n=nums.Count();\n\n        for (int i=0;i<n;i++)\n        {\n            for (int j=target-nums[i];j>=0;j--)\n            {\n                if (dp[j]==-1)continue;   \n                dp[j+nums[i]]=Math.Max(dp[j+nums[i]],dp[j]+1);\n                //finding maximum subarray on each position\n                // till we check all numbers in nums\n            }\n            \n\n        }\n        return dp[target];\n        \n    }\n}\n```
['Dynamic Programming', 'C#']