[C++] [DP] Heavy Comments on Each Line
\nclass Solution {\npublic:\n    // Before reading this, I would highly recommend to take a rought notebook and draw the flow chart of these recursive calls, ch
```\nclass Solution {\npublic:\n    // Before reading this, I would highly recommend to take a rought notebook and draw the flow chart of these recursive calls, change the variables values and check for yourself on how all these recursive values are adding up finally and what value is actually getting returned.\n// It would be a little tedious process but it will help u in Visualising the recursion tree.\n// Solve this code for "mbadm"\n    int minInsert(string& s,int i,int j,vector<vector<int>>& dp) {\n        if(i>=j) { // base case\n            return 0;\n        }\n        if(dp[i][j]!=-1) { // if we have the value already calculated , just return that value\n            return dp[i][j];\n        }\n        if(s[i]==s[j]) { \n            dp[i][j]=minInsert(s,i+1,j-1,dp); // call recursion by decreasing j and increasing i and save the result of dp[i][j] which will be calculated recursively\n            return dp[i][j]; // return the result that we got above \n        }\n        // Now if the chars at s[i] and s[j] are not same/palindrome, NOW WE HAVE 2 DECISION, EITHER ADD A CHARACTER ON THE LEFT SIDE(i pointer) OR ADD A CHARCTER on the RIGHT SIDE(j pointer)\n        int dec1=minInsert(s,i+1,j,dp)+1; // ADDING ONE CHAR ON THE LEFT AND INCREMENT THE DECISION+1 AND calling recursively ON i+1 and j\n        int dec2=minInsert(s,i,j-1,dp)+1; //ADDING ONE CHAR ON THE RIGHT AND INCREMENT THE DECISION+1 AND calling recursively ON i and j+1\n        dp[i][j]=min(dec1,dec2); // SAVING THE MINIMUM OF THE 2 DECISION ON dp[i][j]\n        return min(dec1,dec2); // RETURNING THE MINIMUM DECISION THAT WE GOT\n    } \n    int minInsertions(string s) {\n        int len=s.length(); // calculating length\n        vector<vector<int>>dp(len,vector<int>(len,-1)); // creating 2d vector of size len*len and filling with -1\n        return minInsert(s,0,len-1,dp); // calling recursively \n    }\n};\n```\n\n`TC will be O(len*len) since we are filling the dp[][] table which is of size len*len`
['Dynamic Programming', 'Recursion', 'Memoization', 'C']