516. Longest Palindromic Subsequence
If we figure out the longest palindromic subsequence, then we can tell the miminum number of characters to add or remove to make the string a palindrome. \n\nSo
If we figure out the longest palindromic subsequence, then we can tell the miminum number of characters to add or remove to make the string a palindrome. \n\nSo, we can simply reuse [516. Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/).\n```CPP\nint minInsertions(string s) {\n  return s.size() - longestPalindromeSubseq(s);\n}\nint dp[501][501] = {};\nint longestPalindromeSubseq(string &s) {\n  for (int len = 1; len <= s.size(); ++len)\n    for (int i = 0; i + len <= s.size(); ++i) \n      dp[i][i + len] = s[i] == s[i + len - 1] ? dp[i + 1][i + len - 1] + (len == 1 ? 1 : 2) \n        : max(dp[i][i + len - 1], dp[i + 1][i + len]);\n  return dp[0][s.size()];\n}\n```
[]