Beats 90% cpp sol ✅✅
\n\n# Code\n\nclass Solution {\npublic:\n\n    int solve(vector<int>&nums, int target, int ind, vector<vector<int>>&dp){\n        // base case\n        if(targe
\n\n# Code\n```\nclass Solution {\npublic:\n\n    int solve(vector<int>&nums, int target, int ind, vector<vector<int>>&dp){\n        // base case\n        if(target == 0) return 0;\n        if(ind<0 || target<0) return -1e8;\n        if(dp[ind][target] != -1) return dp[ind][target];\n\n        int take = 1 + solve(nums, target-nums[ind], ind-1, dp); // take wala case\n        int notTake = 0 + solve(nums, target, ind-1, dp); // not take wala case\n\n        return dp[ind][target] = max(take, notTake);\n    }\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 = solve(nums, target, n-1, dp);\n        return ans>0 ? ans : -1;\n    }\n};\n```
['Recursion', 'Memoization', 'C++']