Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

What is the length of the longest common prefix of the two strings obtained by taking all cyclic rotations of "banana" and keeping only the two lexicographically SMALLEST distinct rotations?

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

Correct answer: B. 1

Sort the distinct rotations, take the two smallest, and measure their common prefix character by character. Comparing the first two cyclic shifts in position order instead of sorted order gives a different pair.

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

Exams that ask this topic