Data Structures & AlgorithmsHardCodeforces Div2 D · data structures

Problem: Which structure supports both insertion and 'k-th smallest' queries in O(log n) each?

  1. A. A stack
  2. B. An order-statistics tree or Fenwick tree over compressed values
  3. C. A queue
  4. D. A plain array

Correct answer: B. An order-statistics tree or Fenwick tree over compressed values

An order-statistic tree (or BIT with binary lifting) gives rank and select in logarithmic time.

More Coding Interview Problems questions

Exams that ask this topic