Interval Lookup
Problem
Design IntervalLookup to retain the coverage of constructor-supplied integer intervals and report whether each integer in one or more later batches belongs to that coverage.
Requirements
- Unsorted intervals. Valid intervals may be supplied in any order, and their order does not change lookup results.
- Covered targets. A target is found exactly when at least one supplied interval contains it.
- Closed endpoints. Each interval includes its start, its end, and every integer between them.
- Aligned results.
lookupreturns exactly one boolean per target, and result position describes target position .
API
| Signature | Returns | Behavior |
|---|---|---|
IntervalLookup(intervals: array<[integer, integer]>) | Not applicable | Creates a lookup from zero or more valid intervals. |
lookup(targets: integer[]) | boolean[] | Answers one batch membership query without changing the lookup. |
Examples
Construct IntervalLookup([[10, 12], [1, 3], [6, 8]]).
| Operation | Result |
|---|---|
lookup([2, 5, 10, 12, 13]) | [true, false, true, true, false] |
Constraints
- The constructor receives from
0through100000intervals. - Each interval contains exactly two signed 32-bit integers
[start, end]withstart <= end. - One call receives from
0through100000signed 32-bit targets. - At most
20lookup calls occur per testcase. - Inputs outside these constraints are not judged.
Notes
Calls are sequential. Concurrent access guarantees are outside scope.