Data Structures & AlgorithmsModerateGATE CS · TCS NQT

How many DISTINCT strings are produced by taking all cyclic rotations of "abcabcab" (including the original)?

  1. A. 8
  2. B. 3
  3. C. 10
  4. D. 9

Correct answer: A. 8

Rotations are indexed by the starting position, but a periodic string repeats rotations. If the string is a power of a shorter block of length d (so d divides n), only d rotations are distinct. Counting all n starting positions overcounts such periodic strings.

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

Exams that ask this topic