Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

For the string bcabca, let a rotation be the string obtained by moving a prefix of some length to the end. If rotations are indexed from 0 (rotation i starts at position i), which index gives the lexicographically smallest rotation?

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

Correct answer: B. 2

Compare all rotations or use Booth's algorithm; the smallest rotation begins with the 'abc' pattern at index 2. The index of a rotation is the start position in the original string.

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

Exams that ask this topic