Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Problem: The Z-array of "aaabaab" is computed (z[0] is the full length by convention). What is the sum of z[1] through z[6]?
- A. 6
- B. 13
- C. 4
- D. 11
Correct answer: A. 6
Z-values for "aaabaab" are [–, 2, 1, 0, 2, 1, 0], so z[1..6] sums to 6. Including z[0] = 7 gives 13, counting non-zero entries gives 4, and not stopping at the first mismatch gives 11.
More Coding Interview Problems questions
- Problem: The string "aaaa" has how many distinct palindromic substrings (counting each distinct string once, of any length ≥ 1)?
- Problem: In the tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 3-7, what is the number of leaves (nodes with degree 1)?
- Problem: The subset-sum DP over the values [2, 3, 7, 8, 10] asks: how many subsets have sum exactly 11? The empty subset has sum 0 and is…
- Problem: The array [10, 20, 30, 40, 50] is searched for the first index i whose value is strictly greater than the average of all elements…
- Problem: Bob has the numbers 1 to 10 written on a board. He repeatedly erases the two largest numbers and writes their difference. After 9…
- Problem: The string "racecar" is compressed by storing each character and the number of distinct palindromic substrings of length at least…