<p>You are given a string <code>s</code>. You can convert <code>s</code> to a <span data-keyword="palindrome-string">palindrome</span> by adding characters in front of it.</p>

<p>Return <em>the shortest palindrome you can find by performing this transformation</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "aacecaaa"
<strong>Output:</strong> "aaacecaaa"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "abcd"
<strong>Output:</strong> "dcbabcd"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
	<li><code>s</code> consists of lowercase English letters only.</li>
</ul>

class Solution {
public:

    string shortestPalindrome(string s) {
        string t = s;
        reverse(t.begin(),t.end()); 
        string rev =t;
        if(s == t) return s;
        int m = s.size();

        t=s+ '&' + t;
        int n = t.size();
        vector<int> lps(n);

        int j = 0, i =1;
        while(i<n){
            if(t[i] == t[j]) lps[i] = ++j, i++;
            else{
                if(j){
                    j = lps[j-1];
                }
                else{
                    lps[i] = 0;
                    i++;
                }
            }
   
        }
        // for(auto it:t) cout<<it<<" ";
        // cout<<endl;
        // for(auto it:lps) {
        //     cout<<it<<" ";
        // }
        string ans =rev.substr(0,m-lps.back()) + s;
        
        return ans;
    }
};

//   aacecaa a
// a aacecaa
// 01200012
// aa
11300