Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

How many distinct strings appear among the rotations of "abab" (all n cyclic shifts, including the unshifted string)?

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

Correct answer: A. 2

Periodic strings have fewer distinct rotations than their length: "abab" has period 2, so its 4 rotations collapse to 2 distinct strings. Naively reporting n is the trap.

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

Exams that ask this topic