Probleminterval lookup

Session: Sign in to solve

Solution.txt

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. lookup returns exactly one boolean per target, and result position ii describes target position ii.

API

SignatureReturnsBehavior
IntervalLookup(intervals: array<[integer, integer]>)Not applicableCreates 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]]).

OperationResult
lookup([2, 5, 10, 12, 13])[true, false, true, true, false]

Constraints

  • The constructor receives from 0 through 100000 intervals.
  • Each interval contains exactly two signed 32-bit integers [start, end] with start <= end.
  • One call receives from 0 through 100000 signed 32-bit targets.
  • At most 20 lookup calls occur per testcase.
  • Inputs outside these constraints are not judged.

Notes

Calls are sequential. Concurrent access guarantees are outside scope.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.