Data Structures & AlgorithmsModerateProduct Company SDE · string round

Problem: Is 'cdeab' a rotation of 'abcde'? Check with the substring test below. What is printed?

Problem: Is 'cdeab' a rotation of 'abcde'? Check with the substring test below. What is printed?
s, t = 'abcde', 'cdeab'
print(len(s) == len(t) and t in s + s)
What is printed?
  1. A. False
  2. B. True
  3. C. 1
  4. D. None

Correct answer: B. True

'abcde' + 'abcde' contains 'cdeab' as a substring, so t is a rotation of s. Checking only t in s fails.

More Coding Interview Problems questions

Exams that ask this topic