Data Structures & AlgorithmsHardProduct Company SDE · segment tree

Problem: Which data structure answers range-GCD queries with point updates in O(log n) each?

  1. A. A stack
  2. B. A hash set
  3. C. A linked list
  4. D. A segment tree storing gcd of each node's range

Correct answer: D. A segment tree storing gcd of each node's range

gcd is associative, so each node stores the gcd of its range and queries combine O(log n) nodes.

More Coding Interview Problems questions

Exams that ask this topic