Data Structures & AlgorithmsHardICPC regional · algorithm theory
Problem: Range-add updates and point queries on an array can be done with a Fenwick tree over which representation?
- A. A difference array, where a point query is a prefix sum
- B. The original array with no change
- C. A sorted copy of the array
- D. A hash map of all values
Correct answer: A. A difference array, where a point query is a prefix sum
Adding v to [l, r] becomes two point updates on the difference array, and a point value is the prefix sum of differences.
More Coding Interview Problems questions
- Problem: What is the expected time of Rabin-Karp string matching with a good polynomial hash?
- Problem: How many pairs (i < j) of the array 1..14 have a[i] + a[j] divisible by 7? Run the code. python a = list(range(1, 15))…
- Problem: Which is the worst-case time complexity of the median-of-medians selection algorithm for finding the k-th smallest element of n…
- Problem: What is the worst-case number of comparisons to merge two sorted lists of lengths m and n?
- Problem: For coprime m and n, which identity for Euler's totient function is correct?
- Problem: An undirected graph has vertices 0–7 and edges 0-1, 0-2, 1-2, 2-3, 4-5, 5-6, 6-4, 6-7. How many connected components contain at…