Dp || Take/Not Take || Memoization ✔✔
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n*target)\n Add your space complexity here, e.g. O(n) \
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n*target)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int helper(int i, int target, vector<int>& nums, vector<vector<int>>& dp){\n        if (target==0)return 1;\n        if (i<0)return -1e9;\n        if (dp[i][target]!= -1)return dp[i][target];\n        int take= -1e9;\n        if (nums[i]<=target){\n            take= 1+helper(i-1,target-nums[i],nums,dp);\n        }\n        int notTake= helper(i-1,target,nums,dp);\n        return dp[i][target]= max(take,notTake);\n    } \n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        int n= nums.size();\n        vector<vector<int>> dp(n,vector<int>(target+1,-1));\n        int ans= helper(n-1,target,nums,dp)-1;\n        return max(ans,-1);\n    }\n};\n```
['Array', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++']