Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Find the lexicographically smallest rotation of the string "dcbadcb". What is its starting index (0-based) in the original string, taking the smallest index if several rotations are equal?

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

Correct answer: B. 3

Compare all rotations (or use Booth's algorithm in linear time). Taking the lexicographically largest rotation or the rotation starting at the first 'a' is a wrong heuristic.

More Coding Interview Problems questions

Exams that ask this topic