Data Structures & AlgorithmsModerateGATE CS · ICPC regional
For the string aabaaabaa, what is the sum of the Z-function values Z[1] + Z[2] + ... + Z[n-1] (Z[i] is the longest common prefix of the string and its suffix starting at i)?
- A. 13
- B. 10
- C. 12
- D. 15
Correct answer: C. 12
Each Z[i] is a longest common prefix length, computed by reusing the rightmost matching box. Using prefix-function values instead of Z values gives different numbers.
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 3 does the string abcabcabd have?
- How many substrings of abcabcbb contain no repeated character?
- Evaluate the postfix (reverse Polish) expression 5 1 2 + 4 + 3 -. What is the value?
- Array [5, 2, 8, 1, 9, 3] is processed in one left-to-right pass: each node is deleted if its value is strictly greater than the value of…
- A singly linked list holds 1, 2, 3, 4, 5, 6, 7. Adjacent pairs are swapped in one pass (node 1 with 2, node 3 with 4, and so on; an…
- How many index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] a[j] = 6?