Data Structures & AlgorithmsVery hardGoogle · Flipkart interview

A suffix array of a string of length n is built by putting all suffixes in a list and sorting them with a comparison sort, where each comparison compares strings character by character. What is the worst-case time?

  1. A. O(n² log n)
  2. B. O(n log n)
  3. C. O(n log² n)
  4. D. O(n²)

Correct answer: A. O(n² log n)

The sort makes O(n log n) comparisons, and each can take O(n) time on strings like 'aaaa…a'. Prefix doubling brings it to O(n log² n) or O(n log n), and SA-IS to O(n).

More Coding Interview Problems questions

Exams that ask this topic