Data Structures & AlgorithmsHardProduct Company SDE · segment tree

Problem: What does 'lazy propagation' in a segment tree guarantee for a range-add update?

  1. A. Every leaf is updated immediately
  2. B. Only O(log n) nodes are touched, and pending tags are pushed down on demand
  3. C. Updates cost O(n) each
  4. D. The tree is rebuilt after each update

Correct answer: B. Only O(log n) nodes are touched, and pending tags are pushed down on demand

Tags are stored at canonical nodes and pushed down only when a child is accessed.

More Coding Interview Problems questions

Exams that ask this topic