String Rotation

We'll discuss how to determine if two strings are rotations of one another. We'll go over a brute-force solution and an elegant solution.

String Rotation

Instructions

Create a function that takes in 2 strings as parameters.

Return true if the strings are rotations of each other. Otherwise, return false.

Input: String, String

Output: Boolean

Examples

The following sets of strings are rotations:

"rotation"  "tationro" "tionrota"

"javascript"  "scriptjava"  "iptjavascr"

"RotateMe"  "teMeRota"  "eRotateM"

Hints

  • You may have to spend time thinking about how best to arrange these strings before processing in a loop.
  • Think about ways to short-circuit the check.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.