<p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>

<p>Return <em>the minimum number of steps</em> to make <code>s</code>&nbsp;palindrome.</p>

<p>A&nbsp;<b>Palindrome String</b>&nbsp;is one that reads the same backward as well as forward.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;zzazz&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> The string &quot;zzazz&quot; is already palindrome we do not need any insertions.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;mbadm&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> String can be &quot;mbdadbm&quot; or &quot;mdbabdm&quot;.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;leetcode&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> Inserting 5 characters the string becomes &quot;leetcodocteel&quot;.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 500</code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution {
public:
int dp[1001][1001];
int m;
// int solve(string s1, string s2,int i,int j){
//     if(i==m || j==m) return 0;
//     if(dp[i][j]!=-1) return dp[i][j];
//     if(s1[i]==s2[j]) return dp[i][j]=1+solve(s1,s2,i+1,j+1);
//     else{
//     return dp[i][j]=0+max(solve(s1,s2,i+1,j),solve(s1,s2,i,j+1));
//     } 
// }
int solve(string &s, int i, int j){
    if(i>j) return 0;//i aage gya j s stop
    if(i==j) return 1;// jb dono same pmaajaye to ek ele to palindrome hota hi h
    if(dp[i][j]!=-1) return dp[i][j];

if(s[i]==s[j]) return dp[i][j]=2+solve(s,i+1,j-1);//equal h to 2 ele hogya palindrome to add 2 and call for next
else {
    return dp[i][j]=max(solve(s,i+1,j),solve(s,i,j-1));
    //alg h i and j vla element to dono ko brha and kam krke try and add the max
}
}
    int longestPalindromeSubseq(string s) {
        //atoz r1
        //codewithmik
        memset(dp,-1,sizeof(dp));
        // string s2=s;
        // reverse(s2.begin(),s2.end());
        
        //  m=s.length();
        //return solve(s,s2,0,0); //lcs approch

        return solve(s,0,s.length()-1);//2 point with dp
    }
    int minInsertions(string s) {
        //atoz r1
        //all code same as longest palindrome, just - it from total length
        return s.size()-longestPalindromeSubseq(s);
    }
};
12300