Piddi sa to Que hai (😂) || Hindi 💥 Explaination || Gadha 🫏 Majdoori krva diya || C++
Intuition\n Describe your first thoughts on how to solve this problem. \n How i identify DP ?\n Ankh band kro...arey kro to\n thoda jayda number ko imagine krna
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* How i identify DP ?\n* Ankh band kro...arey kro to\n* thoda jayda number ko imagine krna\n* ab socho en tino pair bnane wale case ke baare me\n* basad machi...dimak me...kya lagta hai..\n* sabhi case se pass hona hoga..sabhi situation se gujrna hoga\n* bas lag gyi dp \n* vaise bhi esme Choice thi hmare pass...to recursion aise hi lg rha \n* esme...optimise krne ke liye DP to hai hi..\u2705\u2705\u2705\u2705\u2705\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* intution feel hua...kya keh rhe\n* kuchh to tha hi nhi intution me \n* \uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\n* aao sidhe,  gadha majdoori ka code dekhte hai...\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(int i,int j, int sum,vector<int> &ip,vector<vector<int>> &t){\n\n        // dekho i start ke liye tha\n        // j end ke liye\n        // jab dono ek dure ko cross kiya yani \n        // hmare pass, koi values hai hi nhi..\n        // simple \uD83D\uDD7A\uD83D\uDD7A\uD83D\uDD7A\uD83D\uDD7A\n        if(i>=j) return 0; \n\n\n        // memo ka step...kyu bhai naam to suna hi hoga \n        // \uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\uD83D\uDE0A\n        if(t[i][j]!=-1) return t[i][j]; \n        \n        // itne variable ki need nhi    \n        // vo tumhe pta hi hai, contest time ka\n        // bas type ho gya tha..\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02\n        int t1=0,t2=0,t3=0,t4=0,t5=0,t6=0; \n        \n        // ab i and j ka check krenge sum ke brabar hia ya nhi\n        if(ip[i]+ip[j]==sum) t1=1+solve(i+1,j-1,sum,ip,t); \n        \n        // phir do pass ke element ka check karenge\n        if(ip[i]+ip[i+1]==sum) t2=1+solve(i+2,j,sum,ip,t);\n\n\n        // phri n, last ke do ka check kr lenge\n        // usi ke hisaab se i and j  move kar denge\n        if(ip[j]+ip[j-1]==sum) t3=1+solve(i,j-2,sum,ip,t);\n\n\n        // jo maximum hoga, vo us state ke DP me store hoga\n        return t[i][j]=max({t1,t2,t3});\n        \n    }\n    int maxOperations(vector<int>& ip) {\n        int n=ip.size(); \n        \n        // minimum itni length to hogi hi\n        // esme direct ek pair banega\n        if(n==2) return 1; \n        \n        // dekho do dp bnayenge \n        // kya abhi bhai...aisa kyu karenge ?\n        // \uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\uD83E\uDD14\n        // smjha dunga chill...\n        vector<vector<int>> tt(n,vector<int> (n,-1));\n        vector<vector<int>> tt2(n,vector<int> (n,-1));\n\n        int t1=0,t2=0,t3=0; \n\n\n        // start ke do element ko leke dp\n        // abhi ye to clear hai n.. aakhir dp hi kyu ?\n        t1=solve(0,n-1,ip[0]+ip[1],ip,tt);\n\n        // dusre call ke liye dp phir se -1 krna padega n\n        // to esiliye ek ka help liya tha,\n        // kai aur tarike hai es kaam ke\n        tt=tt2; \n        \n        // dono aakhiri\n        t2=solve(0,n-1,ip[n-1]+ip[n-2],ip,tt);\n        \n        // same copy paste  \n        // agle call ke liye....\n        tt=tt2; \n        \n        // pehla aakhiri ke liye\n        t3=solve(0,n-1,ip[0]+ip[n-1],ip,tt);\n       \n        // jis tarike me maximum mila, vo return kar denge\n        // \u2705\u2705\u2705\u2705\u2705 Happy Happy \uD83D\uDE0A\n        return max({t1,t2,t3});\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']