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

Notice: string "abc" repeated 0 times is "", repeated 1 time is "abc" and repeated 2 times is "abcabc".

&nbsp;
Example 1:

Input: a = "abcd", b = "cdabcdab"
Output: 3
Explanation: We return 3 because by repeating a three times "abcdabcdabcd", b is a substring of it.


Example 2:

Input: a = "a", b = "aa"
Output: 2


&nbsp;
Constraints:


	1 &lt;= a.length, b.length &lt;= 104
	a and b consist of lowercase English letters.


class Solution:
    def repeatedStringMatch(self, a: str, b: str) -> int:
        res=""
        count=0
        while len(res)<len(b)+len(a):
            count+=1
            res=a*count
            if b in res:
                return count
        return -1
class Solution {
    public int repeatedStringMatch(String a, String b) {
        String copyA = a;
        int count =1;
        int repeat = b.length()/a.length();
        for(int i=0;i<repeat+2;i++){
            if(a.contains(b)){
                return count;
            }
            else{
                a+=copyA;
                count++;
            }
        }
        return -1;

    }
}
class Solution {
public:
    int repeatedStringMatch(string a, string b) {
        int m=a.size(); int n=b.size();
        vector<int>d; int mod=n%m; int h=n/m;

        if(mod==0)
        {d.push_back(h); d.push_back(h+1); }
        else
        { d.push_back(h+1); d.push_back(h+2); }
        string s=""; string t="";

        for(int i=0;i<d[0];i++)
        {s+=a;}
        for(int i=0;i<d[1];i++)
        {t+=a;}

        int i=0; int y1=s.size()-n; int y2=t.size()-n;

        while(i<=y1)
        {
            string x=s.substr(i,n); //cout<<x;
            if(x==b){return d[0]; break;}
            i++;
        }
        i=0;
        while(i<=y2)
        {
            string x=t.substr(i,n); //cout<<"ok1"<<x;
            if(x==b){return d[1]; break;}
            i++;
        }
        return -1;

    }
};
var repeatedStringMatch = function(a, b) {
    const initRepeatTimes = Math.ceil(b.length / a.length);
    const isMatch = (times) => a.repeat(times).includes(b);

    if (isMatch(initRepeatTimes)) return initRepeatTimes;
    if (isMatch(initRepeatTimes + 1)) return initRepeatTimes + 1;
    return -1;
};
Repeated String Match