Given two strings a and b, return the minimum number of times a has to be repeated so that b becomes a substring of the repeated string. If that is impossible, return -1. Repeating "abc" 0 times gives "", once gives "abc", twice gives "abcabc".
Given two strings a and b, return the minimum number of times a has to be repeated so that b becomes a substring of the repeated string. If that is impossible, return -1. Repeating "abc" 0 times gives "", once gives "abc", twice gives "abcabc".
Example 1:
Input: {"a":"abcd","b":"cdabcdab"}
Output: 3
Constraints:
1≤a.length,b.length≤104
a and b consist of lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"a":"abcd","b":"cdabcdab"}
Start with one copy of a (length 4). b has length 8, so we need at least enough copies to cover 8 characters.