# Leetcode 686 - Repeated String Match

Note:

• Use kmp to check substrings.
• There is a pattern in this problem.
• If a.len >= b.len, then we can only repeat a no more than twice.
• If a.len < b.len, then we can only repeat ceil(b.len / a.len) + 1 times.
• For example: a = 'abc', b = "cabcabca". The ans is 4. Because b used part of a at the start, and part of a at the end.

Question:

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”.

Example:

Code: