<p>Given two strings <code>a</code> and <code>b</code>, return <em>the minimum number of times you should repeat string </em><code>a</code><em> so that string</em> <code>b</code> <em>is a substring of it</em>. If it is impossible for <code>b</code>​​​​​​ to be a substring of <code>a</code> after repeating it, return <code>-1</code>.</p>

<p><strong>Notice:</strong> string <code>&quot;abc&quot;</code> repeated 0 times is <code>&quot;&quot;</code>, repeated 1 time is <code>&quot;abc&quot;</code> and repeated 2 times is <code>&quot;abcabc&quot;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> a = &quot;abcd&quot;, b = &quot;cdabcdab&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> We return 3 because by repeating a three times &quot;ab<strong>cdabcdab</strong>cd&quot;, b is a substring of it.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> a = &quot;a&quot;, b = &quot;aa&quot;
<strong>Output:</strong> 2
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= a.length, b.length &lt;= 10<sup>4</sup></code></li>
	<li><code>a</code> and <code>b</code> consist of lowercase English letters.</li>
</ul>

class Solution {
public:
    int strStr(string haystack, string needle) {
        unordered_map <string,int> mp;
        string temp = haystack.substr(0,needle.length());

        mp[temp] = 1;
        if(mp[needle] != 0) return mp[needle]-1;

        for(int i = 1;i + needle.length() - 1<haystack.length();i++){
            temp+=haystack[i + needle.length() - 1];
            temp.erase(0,1);

            if(mp[temp] == 0){
                mp[temp] = i + 1;
            }
            if(mp[needle] != 0) return mp[needle]-1;
        }
        return -1;
    }
    pair<string,int> construct(string a,string b){
        int x = 1;
        string copy = a;
        int si = a.length();
        while(a.length()<b.length() + si - 1){
            a+=copy;
            x++;
        }
        return {a,x};
    }
    pair<string,int> construct2(string a,string b){
        string copy = a;
        int x = 1;
        while(a.length()<b.length()){
            a+=copy;
            x++;
            // cout<<a<<endl;
        }
        return {a,x};
    }
    int repeatedStringMatch(string a, string b) {
        int ret1 = construct(a,b).second;
        string a1 = construct(a,b).first;
        int check1 = strStr(a1,b);

        int ret2 = construct2(a,b).second;
        string a2 = construct2(a,b).first;
        cout<<a2<<endl;
        int check2 = strStr(a2,b);
        if(check2 != -1) return ret2;
        if(check1 != -1) return ret1;
        return -1;
    }
};
97329