[ C++ ] [ Dynamic Programming ] [ Longest Palindromic Subsequence ] [ Longest Common Subsequence ]
Code\n\nclass Solution {\npublic:\n    int lcs(string s,string b){\n    int a=s.size();\n    int m=b.size();\n    int dp[a+1][m+1];\n    for(int i=0;i<a+1;i++){
# Code\n```\nclass Solution {\npublic:\n    int lcs(string s,string b){\n    int a=s.size();\n    int m=b.size();\n    int dp[a+1][m+1];\n    for(int i=0;i<a+1;i++){\n        for(int j=0;j<m+1;j++){\n            if(i==0 || j==0)\n            dp[i][j]=0;\n        }\n    }\n    for(int i=1;i<a+1;i++){\n        for(int j=1;j<m+1;j++){\n            if(s[i-1]==b[j-1])\n            dp[i][j]=1+dp[i-1][j-1];\n            else\n            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);\n        }\n    }\n    return dp[a][m];\n}\n    int longestPalinSubseq(string A) {\n        string s1=A;\n        reverse(s1.begin(),s1.end());\n        return lcs(A,s1);\n    }\n    int minInsertions(string s) {\n        int a=s.length();\n        int b=longestPalinSubseq(s);\n        return a-b;\n    }\n};\n```
['Dynamic Programming', 'C++']