FastPrepCheck String Rotations
Problems/Check String Rotations

Check String Rotations

AMD logoAMD● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks whether two strings are rotations. Lowercase alphabet, empty-string behavior, bounds and interface are authored; approximate source match95%.

Return whether second is a cyclic rotation of first: move some prefix of the first string to its end without changing either part internally. Zero rotation is allowed. Two empty strings are rotations; strings of different lengths are not.

Function

areRotations(first: String, second: String) → boolean

Examples

Example 1

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

Move the prefix ab after cde to obtain cdeab.

Example 2

first = "abcde"second = "abced"return = false

No prefix cut preserves the order needed to produce abced.

Constraints

  • 0 <= first.length <= 2000.
  • 0 <= second.length <= 2000.
  • Both strings contain only lowercase English letters a through z.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public boolean areRotations(String first, String second) {
    // Write your code here.
}
Checking account…