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?
- A. Sum n - sa[i] over suffixes minus the sum of LCP values of adjacent sorted suffixes
- B. Insert every substring into a set in O(n^2) time
- C. Count palindromes with Manacher
- 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
- Problem: Which graph algorithm checks whether a directed graph is a DAG in O(V + E)?
- Problem: What is the expected number of comparisons for a binary search on a sorted array of n = 1000 elements (successful search, worst…
- Problem: What is the time complexity of finding the articulation points and bridges together with one DFS?
- Problem: How many pairs (i < j) of integers in [1, 30] have i + j divisible by 6? Run the code. python print(sum(1 for i in range(1, 31)…
- Problem: How many integers in [1, 10000] are divisible by 9 but not by 27? Run the code. python print(sum(1 for x in range(1, 10001) if x…
- Problem: How many trailing zero bits (factors of 2) does 1000! have? Run the code. python n = 1000 c = 0 p = 2 while p <= n: c += n // p p…