Java/C++ concise solution
This is a direct implementation of longest palindromic subsequence. \n\n\nclass Solution {\n    public String reverseIt(String str)\n     {\n          int i, le
This is a direct implementation of longest palindromic subsequence. \n\n```\nclass Solution {\n    public String reverseIt(String str)\n     {\n          int i, len = str.length();\n         \n          StringBuilder dest = new StringBuilder(len);\n\n          for (i = (len - 1); i >= 0; i--)\n              dest.append(str.charAt(i));\n         \n           return dest.toString();\n    }\n    \n    public int minInsertions(String s) \n    {\n           String s1 = reverseIt(s);\n\n           int dp[][] = new int[s1.length() + 1][s1.length() + 1];\n\n           for(int idx = 0; idx < s1.length() + 1; idx++)\n               dp[0][idx] = 0;\n\n           for(int idx = 0; idx < s.length() + 1; idx++)\n               dp[idx][0] = 0;\n\n           for(int row = 1; row < s.length() + 1; row++)\n           {\n               for(int col = 1; col < s1.length() + 1; col++)\n               {\n                   if(s.charAt(row - 1) == s1.charAt(col - 1))\n                       dp[row][col] = 1 + dp[row - 1][col - 1];\n\n                   else\n                       dp[row][col] = Math.max(dp[row - 1][col], dp[row][col - 1]);\n               }\n           }\n\n           return s.length() - dp[s.length()][s1.length()];\n    }\n}\n```\n\nSame implementation in Cpp\n```\nclass Solution {\npublic:\n    int minInsertions(string s)\n    {\n       string s1 = s;\n       \n       reverse(s1.begin(), s1.end());\n        \n       int dp[s1.size() + 1][s.size() + 1];\n        \n       for(int idx = 0; idx < s1.size() + 1; idx++)\n           dp[0][idx] = 0;\n        \n       for(int idx = 0; idx < s.size() + 1; idx++)\n           dp[idx][0] = 0;\n        \n       for(int row = 1; row < s.size() + 1; row++)\n       {\n           for(int col = 1; col < s1.size() + 1; col++)\n           {\n               if(s[row - 1] == s1[col - 1])\n                   dp[row][col] = 1 + dp[row - 1][col - 1];\n               \n               else\n                   dp[row][col] = max(dp[row - 1][col], dp[row][col - 1]);\n           }\n       }\n        \n       return s.size() - dp[s.size()][s1.size()];\n    }\n};\n```
['C++', 'Java']