Data Structures & AlgorithmsModerateICPC regional · string round
Problem: What is the time complexity of computing the Z-array of a string of length n?
- A. O(n^2)
- B. O(n log n)
- C. O(n sqrt n)
- D. O(n)
Correct answer: D. O(n)
The Z-algorithm reuses the rightmost matched window, so every character is compared a constant number of times.
More Coding Interview Problems questions
- Problem: Which deterministic algorithm finds the global minimum cut of an undirected weighted graph with V vertices in O(V^3) time?
- Count the non-empty subarrays of a = [3, -1, 4, -1, 5, -9, 2, 6] whose sum is divisible by 5, using prefix sums taken modulo 5. python…
- Items (weight, value) are (5,10), (4,7), (6,12), (3,4) and the knapsack capacity is 10. Each item may be taken at most once. Run the exact…
- Binary string s = "1101001110001011". Find the length of the longest contiguous substring that contains equally many 0s and 1s. python…
- Intervals (start, end) are compatible when one ends at or before the other starts. Run the earliest-finish greedy on the list below and…
- Coins of denominations 1, 3 and 4 are available with unlimited supply. For the amount 6, run the DP that finds the minimum number of coins…