Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

For "dcbadcba", among its rotations, which starting index i (0-based, the rotation s[i:] + s[:i]) gives the lexicographically smallest string? Report the first such index.

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

Correct answer: C. 3

Compare all rotations; the smallest one starts at the minimal letter 'a' followed by the smallest continuation. Booth's algorithm reports the same index in linear time.

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

Exams that ask this topic