Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Sort all suffixes of "banana" lexicographically. What is the sum of the lengths of the longest common prefixes of each pair of adjacent suffixes in that order?
- A. 3
- B. 7
- C. 15
- D. 6
Correct answer: D. 6
Sorted suffixes: a, ana, anana, banana, na, nana, with adjacent LCPs 1, 3, 0, 0, 2 = 6. Summing LCPs over all pairs gives 7, 3 is only the largest LCP ('ana'), and 15 is the number of distinct substrings.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many distinct substrings of length 4 does "abcabcabca" contain?
- How many proper borders (non-empty proper prefixes that are also suffixes) does "abaabaaba" have?
- Using z[0] = 0, what is the sum of the Z-function values over all indices of "aabxaayaab"?
- Starting at index 0 of [3, 2, 1, 0, 4], each value a[i] allows a jump of at most a[i] steps forward. Can the last index be reached?
- What is the maximum value of a[i] + a[j] over pairs with j - i >= 2 in [5, 1, 8, 2, 9, 3]?
- What is the minimum number of elements that must be deleted from [4, 4, 1, 1, 1, 2, 3, 3] so the remaining values are pairwise distinct?