Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Problem: The Z-function of a string s is defined as z[i] = the length of the longest common prefix of s and s[i:]; z[0] is conventionally the full length. For s = "aabxaabxcaabxaabxay", count the indices i ≥ 1 with z[i] ≥ 4.
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Z-values are computed in linear time with a window [l, r). Counting positions where the first character matches (z[i] ≥ 1) is a much looser condition.
More Coding Interview Problems questions
- Problem: Count the distinct non-empty substrings of "abcabc" (two substrings are the same if their letters are identical, regardless of…
- Problem: How many windows of length 3 in the text "bacacbaab" are anagrams of the pattern "aab" (same letters with the same…
- Problem: What is the length of the longest substring of "eceebaabbccbdeeabe" that contains at most 2 distinct characters?
- Problem: Find the lexicographically smallest rotation of the string "dcbadcb". What is its starting index (0-based) in the original…
- Problem: The longest common subsequence of "ABCBDAB" and "BDCABA" has length L. What is L?
- Problem: From the string "aaabbbaabbccaa", you may delete the minimum number of characters so that no two adjacent characters are equal…