<p>Given two strings <code>s</code> and <code>goal</code>, return <code>true</code> <em>if and only if</em> <code>s</code> <em>can become</em> <code>goal</code> <em>after some number of <strong>shifts</strong> on</em> <code>s</code>.</p>

<p>A <strong>shift</strong> on <code>s</code> consists of moving the leftmost character of <code>s</code> to the rightmost position.</p>

<ul>
	<li>For example, if <code>s = &quot;abcde&quot;</code>, then it will be <code>&quot;bcdea&quot;</code> after one shift.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "abcde", goal = "cdeab"
<strong>Output:</strong> true
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "abcde", goal = "abced"
<strong>Output:</strong> false
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length, goal.length &lt;= 100</code></li>
	<li><code>s</code> and <code>goal</code> consist of lowercase English letters.</li>
</ul>

class Solution {
    vector<int> findlps(string s){
        int n = s.length();
        vector<int> lps(n, 0);
        int suf = 1, pre = 0;
        while(suf < n){
            if(s[suf] == s[pre]){
                lps[suf] = pre+1;
                suf++;
                pre++;
            }
            else{
                if(pre == 0) suf++;
                else pre = lps[pre-1];
            }
        }
        return lps;
    }
    int firstOccurence(string &needle, string &haystack){
        int n = needle.size();
        int m = haystack.size();
        vector<int> lps = findlps(haystack);
        int i =0, j =0;
        while(i< n && j < m){
            if(needle[i] == haystack[j]){
                i++;
                j++;
            }
            else{
                if(j == 0) i++;
                else j = lps[j-1];
            }
        }
        if(j == m) return i-j;
        return -1;
    }
public:
    bool rotateString(string s, string goal) {
        if(s.length() != goal.length()) return false;
        goal += goal;
        int i = firstOccurence(goal, s);
        return i != -1;
    }
};
7800