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?
- A. O(n² log n)
- B. O(n log n)
- C. O(n log² n)
- 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
- What is the solution of T(n) = T(n/2) + T(n/4) + n?
- Edge case: Java's int arithmetic wraps around in two's complement. The Python code below emulates exactly what this Java line computes…
- Edge case: Array sorting and parseInt in JavaScript. javascript console.log([3, 20, 100].sort().join(","), [1, 2…
- Problem: Answer sub-rectangle sum queries on a matrix in O(1) each with a 2-D prefix-sum table. python m = [[3, 0, 1, 4], [5, 6, 3, 2]…
- Problem: A van with fixed capacity picks up and drops passengers; trip [n, from, to] carries n passengers from km 'from' to km 'to' (they…
- Problem: Start at index 0 and finish at the last index; from i you may jump to any of i+1..i+k. Maximise the sum of visited values…