C++ | Extra Small | Dynamic Programming | String
Intuition\n Describe your first thoughts on how to solve this problem. \nDynamic programming\n# Approach\n Describe your approach to solving the problem. \n   s
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDynamic programming\n# Approach\n<!-- Describe your approach to solving the problem. -->\n   size of string - the Longest Palindromic Subsequence\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n       O(n*m)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n       O(n*m)\n\n# Code\n```\nclass Solution {\npublic:\n    int minInsertions(string s) {\n        vector<vector<int>> dp(s.size(),vector<int>(s.size(),0));\n        string t=s;\n        reverse(t.begin(),t.end());\n        for(int i=0;i<s.size();i++)for(int j=0;j<t.size();j++)\n            (s[i]==t[j])?(dp[i][j]= 1+((i-1>=0 && j-1>=0)?dp[i-1][j-1]:0)):( dp[i][j]=max(((i>0)?dp[i-1][j]:0),((j>0)?dp[i][j-1]:0)));\n        return s.size()-dp[s.size()-1][t.size()-1];\n    }\n};\n```
['C++']