Description
Given strings a and b, find minimum number of times a needs to be repeated such that b is a substring, or -1 if impossible.
Examples
Input:
a = "abcd", b = "cdabcdab"Output:
3Explanation:
After 3 repeats: 'abcdabcdabcd' contains 'cdabcdab'.
Input:
a = "abc", b = "cabcab"Output:
3Explanation:
After 3 repeats: 'abcabcabc' contains 'cabcab' starting at index 2.
Input:
a = "xyz", b = "pqr"Output:
-1Explanation:
No matter how many times 'xyz' is repeated, it will never contain 'pqr' since they share no common characters.
Constraints
- •
1 ≤ a.length, b.length ≤ 10⁴