← 返回 microsoft 的题目列表Rotate String (variant with two string arrays)
类型:online_judge
You are given two string arrays A and B of the same length n. For each index i, you may rotate A[i] any number of times (cyclic shift).
Determine whether there exists a choice of rotations such that the rotated A equals B element-wise.
Return true/false.
You are expected to run tests after implementation.
Constraints (reasonable for interview):
1 <= n <= 2e5
1 <= len(A[i]), len(B[i]) <= 1e5, total length <= 2e5
Alphabet: lowercase letters (negotiable)
Examples:
Input: A = ["abc", "aa"], B = ["bca", "aa"] -> true
Input: A = ["abc"], B = ["acb"] -> false
Example
Input
2
abc aa
bca aa
Output
true