<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 lcs(string &text1, string &text2) {
    int n1 = text1.size();
    int n2 = text2.size();
    int dp[n2+1];
    memset(dp,0,sizeof(dp));
    for (int i = n1 - 1; i >= 0; i--) {
        int last_diagonal = 0;
        for (int j = n2 - 1; j >= 0; j--) {
            int temp = dp[j];
            if (text1[i] == text2[j]) dp[j] = 1 + last_diagonal;
            else dp[j] = max(dp[j], dp[j + 1]);
            last_diagonal = temp;
        }
    }

    return dp[0];
}

// bd
// db

int minInsertions(string s) {
    string str = s;
    reverse(str.begin(),str.end());
    int x = lcs(s,str);
    int n = s.size();
    return n - x;
}
};
7700