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?

  1. A. A Fenwick tree over compressed values (or an ordered multiset with rank queries)
  2. B. A plain stack
  3. C. A hash map alone
  4. 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

Exams that ask this topic