FastPrepRotation with at Most Three Mismatches

Rotation with at Most Three Mismatches

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

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) → boolean

Examples

Example 1

first = "abcde"second = "cdeab"return = true

A cyclic shift produces an exact match.

Example 2

first = "abcdef"second = "xbcyez"return = true

The zero rotation differs at exactly three positions.

Constraints

  • 0 <= first.length, second.length <= 2000
  • The strings contain lowercase English letters.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public boolean similarAfterRotation(String first, String second) {
    // Write your code here.
}
first"abcde"
second"cdeab"
expectedtrue
Checking account…