Data Structures & AlgorithmsVery hardICPC regional · strings

Problem: Which approach computes the number of distinct substrings of a string of length n in O(n log n) with a suffix array?

  1. A. Sum n - sa[i] over suffixes minus the sum of LCP values of adjacent sorted suffixes
  2. B. Insert every substring into a set in O(n^2) time
  3. C. Count palindromes with Manacher
  4. D. Use Kadane's algorithm

Correct answer: A. Sum n - sa[i] over suffixes minus the sum of LCP values of adjacent sorted suffixes

Distinct substrings equal total suffix lengths minus the adjacent LCP values, since shared prefixes are counted once.

More Coding Interview Problems questions

Exams that ask this topic