<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 {
    vector<int>computelps(string temp , vector<int>&lps){
        int n = temp.size();
        int length =0;
        int i =1;
        while(i<n){
            if(temp[i]==temp[length]){
                length++;
                lps[i] = length ; 
                i++;
            }
            else{
                if(length!=0){
                    length = lps[length-1];
                }
                else{
                    lps[i]=0;
                    i++;
                }
                
            }
        }

        return lps;
    }
public:
    string shortestPalindrome(string s) {
        string t = s;
        reverse(t.begin(), t.end());
        string  temp = s+"#"+t;
        vector<int>lps(temp.size() ,0);

        computelps(temp , lps);

        int longest_palindrome_from_0th = lps[temp.size()-1];

        int size_left = s.size() - longest_palindrome_from_0th;

        string right_portion = s.substr(longest_palindrome_from_0th , size_left );
        reverse(right_portion.begin(), right_portion.end());
        return right_portion+s;
    }
};
13200