4105. Repeated String Match II
DifficultyHard
Description
You are given two strings a and b consisting of lowercase English letters, and two integers x and y.
Return true if the string formed by repeating b exactly y times (b * y) is a substring of the string formed by repeating a exactly x times (a * x). Otherwise, return false.
A substring is a contiguous non-empty sequence of characters within a string.
Example 1:
Input: a = "ab", b = "abab", x = 2, y = 1
Output: true
Explanation:
a * x = "ab" * 2 = "abab"b * y = "abab" * 1 = "abab"- They are identical, so
b * yis a substring ofa * x. Thus, the answer istrue.
Example 2:
Input: a = "abc", b = "bc", x = 2, y = 3
Output: false
Explanation:
a * x = "abc" * 2 = "abcabc"b * y = "bc" * 3 = "bcbcbc"- The answer is
falseasb * y = "bcbcbc"is not a substring ofa * x = "abcabc".
Example 3:
Input: a = "abcd", b = "cdab", x = 2, y = 1
Output: true
Explanation:
a * x = "abcd" * 2 = "abcdabcd"b * y = "cdab"appears ina * x = "abcdabcd"at indices[2..5]. Thus, the answer istrue.
Constraints:
1 <= a.length <= 1001 <= b.length <= 1001 <= x <= 1091 <= y <= 109aandbconsist of lowercase English letters.
Solutions
Solution 1
1 | |
1 | |
1 | |
1 | |