Range Module
Design a data structure that tracks a set of half-open intervals [left, right) over the real numbers. Implement RangeModule with three operations: addRange(left, right) begins tracking every number in [left, right); queryRange(left, right) returns true only if every number in [left, right) is currently tracked; removeRange(left, right) stops tracking every number in [left, right).
Open official problem prompt ↗Maintain a set of tracked real-number ranges under additions and removals, and answer whether an arbitrary range is fully covered.
Think of a highlighter on a long ruler: addRange paints a stretch (overlapping strokes fuse into one), removeRange erases a stretch (erasing the middle of a stroke leaves two shorter strokes), and queryRange asks whether a section is painted end to end with no gaps.
- Input
- addRange(10, 20); removeRange(14, 16); queryRange(10, 14); queryRange(13, 15); queryRange(16, 17)
- Output
- [null, null, true, false, true]
- Why
- After adding [10,20) and removing [14,16), the tracked set is [10,14) plus [16,20); [10,14) is fully covered, [13,15) straddles the removed hole, and [16,17) sits inside [16,20).
1 <= left < right <= 10^9At most 10^4 calls total to addRange, queryRange, and removeRange