Data Structures & AlgorithmsHardCodeforces Div2 D · data structures
Problem: Which data structure supports inserting values, deleting values and answering 'how many stored values are at most x' in O(log n) each?
- A. A Fenwick tree over compressed values (or an ordered multiset with rank queries)
- B. A plain stack
- C. A hash map alone
- D. A sorted array with linear search
Correct answer: A. A Fenwick tree over compressed values (or an ordered multiset with rank queries)
A Fenwick tree over compressed coordinates gives prefix counts with point updates in O(log n). A hash map cannot answer range counts.
More Coding Interview Problems questions
- Problem: Which statement about the Z-function of a string of length n is correct?
- Problem: How many subarrays of [2, 3, 4, 5] contain exactly one odd number? Run the code. python a = [2, 3, 4, 5] print(sum(1 for i in…
- Problem: What is the length of the longest subarray of [1, 2, 3, 4, 5] whose sum is at most 10? Run the two-pointer code. python a = [1…
- Problem: How many pairs (i < j) of [1, 2, 3, 4, 5] have a[i] a[j] at most 10? Run the code. python a = [1, 2, 3, 4, 5] print(sum(1 for i…
- Problem: How many distinct values appear among the minima of all subarrays of [3, 1, 2]? Run the code. python a = [3, 1, 2] mins =…
- Problem: What is the maximum value of a[i] + a[j] - (j - i) over pairs i < j of a = [1, 3, -2, 5]? Run the code. python a = [1, 3, -2, 5]…