✅C++ || Recursion->Memoization->Tabulation || 01-Knapsack
Method - 1 [Recursion]\n\n\nT->O(Expo) && S->O(n) [Recursion stack space]\n\nclass Solution {\npublic:\n    int f(int i,int count,vector& st,vector>& eve,int n)
# Method - 1 [Recursion]\n![image](https://assets.leetcode.com/users/images/f4931dd3-0490-45f9-b03d-477b5e9d4210_1664628217.7387586.png)\n\n**T->O(Expo) && S->O(n) [Recursion stack space]**\n\nclass Solution {\npublic:\n    int f(int i,int count,vector<int>& st,vector<vector<int>>& eve,int n){\n        if(i>=n || count==2) return 0;\n        int ind=lower_bound(st.begin(),st.end(),eve[i][1]+1)-st.begin();\n        int pick = eve[i][2] + f(ind,count+1,st,eve,n);\n        int notpick = f(i+1,count,st,eve,n);\n        return max(pick,notpick);\n    }\n    \n    int maxTwoEvents(vector<vector<int>>& eve) {\n        int n=eve.size();\n        sort(eve.begin(),eve.end());\n        vector<int> st;\n        for(auto i: eve) st.push_back(i[0]);\n        return f(0,0,st,eve,n);\n    }\n};\n\n# Method - 1 [Memoization]\n![image](https://assets.leetcode.com/users/images/cd7e9a79-dfd4-4f12-a3e4-7c97e528f8f6_1664628746.6609268.png)\n\n**T->O(3n) && S->O(3n) + O(n) [Recursion stack space]**\n\n\tclass Solution {\n\tpublic:\n\t\tint f(int i,int count,vector<int>& st,vector<vector<int>>& eve,int n,vector<vector<int>>& dp){\n\t\t\tif(i>=n || count==2) return 0;\n\t\t\tif(dp[i][count]!=-1) return dp[i][count];\n\t\t\tint ind=upper_bound(st.begin(),st.end(),eve[i][1])-st.begin();\n\t\t\tint pick = eve[i][2] + f(ind,count+1,st,eve,n,dp);\n\t\t\tint notpick = f(i+1,count,st,eve,n,dp);\n\t\t\treturn dp[i][count]=max(pick,notpick);\n\t\t}\n\n\t\tint maxTwoEvents(vector<vector<int>>& eve) {\n\t\t\tint n=eve.size();\n\t\t\tsort(eve.begin(),eve.end());\n\t\t\tvector<int> st;\n\t\t\tvector<vector<int>> dp(n,vector<int>(3,-1));\n\t\t\tfor(auto i: eve) st.push_back(i[0]);\n\t\t\treturn f(0,0,st,eve,n,dp);\n\t\t}\n\t};\n\t\n# Method -3 [Tabulation]\t\n![image](https://assets.leetcode.com/users/images/64abbcad-9ecb-4e51-8ed1-e2e0533a30a4_1664629043.2080193.png)\n\n\n**T->O(3n) && S->O(3n)**\n\n\tclass Solution {\n\tpublic:\n\t\tint maxTwoEvents(vector<vector<int>>& eve) {\n\t\t\tint n=eve.size();\n\t\t\tsort(eve.begin(),eve.end());\n\t\t\tvector<int> st;\n\t\t\tvector<vector<int>> dp(n+1,vector<int>(3,0));\n\t\t\tfor(auto i: eve) st.push_back(i[0]);\n\t\t\tfor(int i=n-1;i>=0;i--){\n\t\t\t\tfor(int count=1;count>=0;count--){\n\t\t\t\t\tint ind=upper_bound(st.begin(),st.end(),eve[i][1])-st.begin();\n\t\t\t\t\tint pick = eve[i][2] + dp[ind][count+1];\n\t\t\t\t\tint notpick = dp[i+1][count];\n\t\t\t\t\tdp[i][count]=max(pick,notpick);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn dp[0][0];\n\t\t}\n\t};\n
['Binary Search', 'Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']