Data Structures & AlgorithmsVery hardICPC regional · data structures

Problem: Which data structure supports adding a value to a prefix of an array and finding the first index whose value is at least x, each in O(log n)?

  1. A. A stack
  2. B. A hash map keyed by index
  3. C. A segment tree with lazy propagation storing range maxima
  4. D. A linked list

Correct answer: C. A segment tree with lazy propagation storing range maxima

Range-add lazy tags plus maxima in each node let a descent find the first index with value at least x in O(log n).

More Coding Interview Problems questions

Exams that ask this topic