Data Structures & AlgorithmsHardGATE CS · TCS NQT

A string is compared to a pattern by repeatedly rotating its first character to the end. How many distinct rotations of abab exist (identity included)?

  1. A. 3
  2. B. 1
  3. C. 2
  4. D. 4

Correct answer: C. 2

abab has period 2, so rotations 0 and 2 coincide, and rotations 1 and 3 coincide. Counting every index as distinct gives four.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic