Search⌘ K
AI Features

Solution: Range Module

Discover how to build a Range Module that tracks intervals using half-open ranges. Learn to add, remove, and query intervals efficiently by merging and splitting ranges. Understand the use of binary search to optimize interval operations and manage overlapping intervals with clear time and space complexity insights.

Statement

Design a Range Module data structure that effectively tracks ranges of numbers using half-open intervals and allows querying these ranges. A half-open interval [left,right)[left, right) includes all real numbers nn where leftn<rightleft\leq n <right.

Implement the RangeModule class with the following specifications:

  • Constructor(): Initializes a new instance of the data structure.

  • Add Range(): Adds the half-open interval [left, right)[left,~right) ...