← 返回 walmartlabs 的题目列表Range Module (LC 715)
类型:qbank
The first technical phone screen used LC 715 Range Module unchanged: implement add, remove, and full-coverage query operations over tracked half-open intervals. The sharp edge is boundary correctness when a new operation overlaps, touches, splits, or consumes existing ranges.
Requirements
Implement a RangeModule that tracks real-number intervals with three operations:
addRange(left, right) tracks every number in the half-open interval [left, right). Overlapping tracked intervals must behave as one covered range.
queryRange(left, right) returns true only when every number in [left, right) is currently tracked.
removeRange(left, right) stops tracking every number in [left, right), including the middle of a previously tracked interval.
Examples
RangeModule rangeModule = new RangeModule()
rangeModule.addRange(10, 20)
rangeModule.removeRange(14, 16)
rangeModule.queryRange(10, 14) // true
rangeModule.queryRange(13, 15) // false
rangeModule.queryRange(16, 17) // true
Notes
This was the unchanged LC 715 problem.
Keeping separate low- and high-endpoint arrays can trigger complicated branches around the current, previous, and next insertion positions.
A single flattened endpoint array makes inside-versus-outside state visible from insertion-index parity and can eliminate manual merge-removal loops.
Be precise about bisect_left versus bisect_right; most implementation difficulty comes from touching endpoints, exact-boundary removals, and ranges that split existing coverage.
Preparation
Drill half-open interval cases by hand: touching endpoints, a new range spanning several tracked ranges, removing an inner segment, and removing across multiple ranges.
Reimplement the flattened-endpoint representation from a blank file and explain why insertion-index parity identifies whether a point is currently covered.
Write a compact boundary-case test matrix before coding so each add, query, and remove operation has a falsifiable expected result.