Data Structures & AlgorithmsHardGATE CS · ICPC regional

Among all cyclic rotations of "bcabca" (there are n = 6 of them, including the original), what is the 0-based index i of the lexicographically smallest rotation s[i..] + s[..i]? If several are equal, take the smallest index.

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

Correct answer: B. 2

Compare all rotations, or use Booth's algorithm (O(n)) on s + s. The smallest index among equal minima matters here, and the rotation starting at the smallest letter is not always the smallest rotation.

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

Exams that ask this topic