Easy Solution Of JAVA 🔥C++ 🔥DP 🔥Beginner Friendly
\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n\nclass Solution {\n        public int minInsertions(String s) {\n        StringBuilder sb = new StringBuilder(s);\n    
\n\n# Code\nPLEASE UPVOTE IF YOU LIKE.\n```\nclass Solution {\n        public int minInsertions(String s) {\n        StringBuilder sb = new StringBuilder(s);\n        sb.reverse();\n        String rev = sb.toString();\n        int n = s.length();\n        int[][] dp = new int[n+1][n+1];\n        for(int i=1;i<=n;i++) {\n            for(int j=1;j<=n;j++) {\n                int val = -1;\n                if(s.charAt(i-1) == rev.charAt(j-1)) {\n                    val = 1 + dp[i-1][j-1];\n                }\n                else {\n                    val =  Math.max(dp[i-1][j], dp[i][j-1]);\n                }\n                dp[i][j] = val;\n            }\n        }\n        int lcsCount = dp[n][n];\n       \n        int minInsertion = n - lcsCount; \n        return minInsertion;\n    }\n}\n```\nC++\n```\nclass Solution {\npublic:\n\tint lcs(string s1, string s2) {\n\t\tint n=s1.size(),m=s2.size();\n\t\tvector<vector<int>> dp(n,vector<int>(m,0));\n\t\tfor(int i=0;i<n;i++){\n\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\tif(!i  || !j){\n\t\t\t\t\tif(s1[i]==s2[j]) dp[i][j]=1;\n\t\t\t\t\telse{\n\t\t\t\t\t\tif(!i && !j) dp[0][0]=0;\n\t\t\t\t\t\telse if(!i && j) dp[0][j]=dp[0][j-1];\n\t\t\t\t\t\telse if(i && !j) dp[i][0]=dp[i-1][0];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif(s1[i]==s2[j]) dp[i][j]=1+dp[i-1][j-1];\n\t\t\t\t\telse dp[i][j]=max(dp[i-1][j],dp[i][j-1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[n-1][m-1];  \n\t}\n\n\tint minInsertions(string s) {\n\t\treturn s.size()-lcs(s,string(s.rbegin(),s.rend()));\n\t}\n};\n\n```
['Dynamic Programming', 'C++', 'Java']