<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:
    bool isPalindrome(string s){
        string t = s;
        reverse(s.begin(), s.end());
        return s == t;
    }

    int findLCS(string s1, string s2){
        int n1 = s1.size(); int n2 = s2.size();

        vector<vector<int> > dp(n1+1, vector<int> (n2+1, 0));

        for(int i=0; i<=n1; i++) dp[i][0] = 0;
        for(int i=0; i<=n2; i++) dp[0][i] = 0;

        for(int i=1; i<=n1; i++){
            for(int j=1; j<=n2; j++){
                int res = 0;
                if(s1[i-1] == s2[j-1])
                    res = 1 + dp[i-1][j-1];
                else
                    res = max(dp[i-1][j], dp[i][j-1]);
                dp[i][j] = res;
            }
        }

        return dp[n1][n2];
    }

    int minInsertions(string s) {
        if(isPalindrome(s)) return 0;
        string t = s;
        reverse(t.begin(), t.end());
        // what if we do -> string_length - lcs
        int lcs = findLCS(s, t);
        return s.size() - lcs;
    }
};
25300