✅✅ BEST C++ solution DP ( 2 approach )  Memorization vs Tabulation 💯💯 ⬆⬆⬆⬆
\n\n# Code\n\n#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n    int solveMem(string& a, string& b, int i, int j, vvi& dp)   {\n  
\n\n# Code\n```\n#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\npublic:\n    int solveMem(string& a, string& b, int i, int j, vvi& dp)   {\n        if(i == a.length() || j == b.length())  return 0;\n        if(dp[i][j] != -1)  return dp[i][j];\n        if(a[i] == b[j])    dp[i][j] = 1 + solveMem(a, b, i+1, j+1, dp);\n        else    dp[i][j] = max(solveMem(a, b, i+1, j, dp), solveMem(a, b, i, j+1, dp));\n        return dp[i][j];\n    }\n\n    int solveTab(string& a, string& b)  {\n        vvi dp(a.length() + 1, vi(a.length() + 1, 0));\n        \n        for(int i=a.length()-1; i>=0; i--)  {\n            for(int j=b.length()-1; j>=0; j--)  {\n                if(a[i] == b[j])    dp[i][j] = 1 + dp[i+1][j+1];\n                else    dp[i][j] = max(dp[i+1][j], dp[i][j+1]);\n            }\n        }\n\n        return dp[0][0];\n    }\n\n\n    int minInsertions(string s) {\n        string rev = s;\n        reverse(rev.begin(), rev.end());\n        vvi dp(s.length(), vi(s.length(), -1));\n        return s.length() - solveMem(s, rev, 0, 0, dp);\n\n        // return s.length() - solveTab(s, rev);\n    }\n};\n```
['C++']