<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>

int dp[1001][1001];
int solve(string &s,int i,int j){
    if(i==j){
        return 0;
    }

    if(i>j){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int ans=0;
    if(s[i]==s[j]){
        ans=solve(s,i+1,j-1);
    }else{
        ans=1+min(solve(s,i+1,j),solve(s,i,j-1));
    }
    dp[i][j]=ans;
    return ans;
}

class Solution {
public:
    int minInsertions(string s) {
        memset(dp,1001,sizeof(dp));
      //return solve(s,0,s.size()-1);
      for(int i=0;i<s.size();i++){
        for(int j=0;j+i<s.size();j++){
            if(i==0){
                dp[j][i+j]=0;
            }else if(i==1){
                dp[j][j+i]=1;
                if(s[j]==s[i+j]){
                    dp[j][j+i]=0;
                }
            }else if(s[j]==s[j+i]){
                dp[j][j+i]=dp[j+1][j+i-1];
            }else{
                dp[j][i+j]=1+min(dp[j+1][j+i],dp[j][j+i-1]);
            }
        }
      }
      return dp[0][s.size()-1];
    }
};
11800