Rotation with at Most Three Mismatches
Problem statement
Return whether second can be cyclically rotated so that it differs from first at no more than three positions.
The strings must have equal length. A rotation by zero positions is allowed.
Function
similarAfterRotation(first: String, second: String) → booleanExamples
Example 1
first = "abcde"second = "cdeab"return = trueA cyclic shift produces an exact match.
Example 2
first = "abcdef"second = "xbcyez"return = trueThe zero rotation differs at exactly three positions.
Constraints
0 <= first.length, second.length <= 2000- The strings contain lowercase English letters.