Member-only story

Interview question: Use Python to determine if two strings are a rotation mutually

Crystal X
2 min readMay 17, 2023

--

String manipulation problems are very common problems that an applicant will be asked to solve in a coding interview. In an interview the applicant will be provided with two strings and will be asked to develop an algorithm to determine if they are rotations of each other.

A string is said to be a rotation of another string if:-

  1. Both strings have equal length and are composed of the same characters.
  2. The second string can be obtained by rotating the first string around a certain character.

The psuedocode to find out if two strings are rotations of each other is:-

  1. Define the two strings, s1 and 22, which are going to be tested for rotation mutuality.
  2. Defined the function, checkRotation, which will accept the two strings as input.
  3. Defined the variable, temp, which is an empty string.
  4. If the two strings are not the same length then the two strings are not mutually exclusive.
  5. Add the string, s1, to itself.
  6. If the string, s2, is in temp then the two strings are a rotation mutually, otherwise they are not.

The code in Python to see if two strings are rotation mutually is below:-

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet