Take & not-take using recursion & memorisation - Explained
\n# Approach \n\n- This is classic take and not-take problem\n- Iterate over each element using recursion\n- consider each item as taken once and once with out 
\n# Approach \n\n- This is classic take and not-take problem\n- Iterate over each element using recursion\n- consider each item as taken once and once with out considering the item\n- Store the result in a global varable for future use\n    \n```\nvector<vector<int>> dp;\n\nint solve(vector<int>& nums, int i, int target){\n    if(target == 0) return 0;                          // when target is zero that means we found set of elements that sum up to target   \n    if(target < 0 || i >= nums.size()) return -1001;   // if target is less then 0 or i is greater than nums size then its invalid case and just return with very small number     \n    if(dp[i][target] != - 1) return dp[i][target];     // if already seen this condition then just return the stored result\n    int take = 1 + solve(nums, i+1, target - nums[i]); // when we take, we add 1 to the count and decrease target by nums[i]\n    int notTake = solve(nums, i+1, target);            // when not-take, simple move to next element\n    return dp[i][target] = max(take, notTake);         // save the max result for future use\n}\n\nint lengthOfLongestSubsequence(vector<int>& nums, int target) {\n    dp.resize(1001, vector<int>(1001, -1));            // initialise dp with -1\n    int ans = solve(nums, 0, target);                  // get the result with starting i = 0\n    return (ans > 0)?ans: -1;                          // return -1 if the ans is less than equal to 0, otherwise return ans\n}\n```\n\n\n---\n\n\n<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:\nhttps://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted\n\n---
['C++']