Implement a Range Module with Add, Query, and Remove
Company: Walmart Labs
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
## Process Range Tracking Operations
Implement `processRanges(operations) -> queryResults`.
The tracker is initially empty. Process every operation from left to right. Each operation is a three-element JSON-compatible array:
```text
[type, left, right]
```
- `type` is exactly `"add"`, `"remove"`, or `"query"`.
- `left` and `right` are integers with `1 <= left < right <= 1,000,000,000`.
- Every range is half-open: `[left, right)` includes `left` and excludes `right`.
Operation semantics:
- `add` starts tracking every number in `[left, right)`. Already tracked portions remain tracked.
- `remove` stops tracking every number in `[left, right)`. Tracked portions outside that range remain tracked.
- `query` asks whether every number in `[left, right)` is currently tracked.
Return one Boolean for each `query` operation, in the same order those queries appear. `add` and `remove` operations do not add anything to the result.
### Constraints
- `0 <= operations.length <= 10,000`.
- Every operation has exactly three elements and satisfies the encoding and endpoint rules above.
- Adjacent tracked ranges have no gap because `[a, b)` and `[b, c)` together cover `[a, c)`.
- The input must not be mutated.
- Aim for logarithmic boundary search plus work proportional to the stored ranges changed by an update.
```hint Test the endpoints
Before choosing a representation, trace cases where ranges are disjoint, touch at one endpoint, overlap, contain one another, or are split by removal.
```
### Examples
```text
operations = [
["add", 10, 20],
["remove", 14, 16],
["query", 10, 14],
["query", 13, 15],
["query", 16, 17]
]
queryResults = [true, false, true]
```
```text
operations = [
["query", 1, 2],
["add", 5, 10],
["add", 10, 12],
["query", 5, 12],
["remove", 3, 20],
["query", 5, 6]
]
queryResults = [false, true, false]
```
Quick Answer: Implement a range tracker that adds, removes, and queries half-open integer intervals while preserving coverage across overlaps and adjacent endpoints. Explore interval invariants, splitting and merging updates, ordered search, deterministic query results, and boundary-focused tests.