Target Interval Conflict
Problem statement
You are given a target half-open interval [target[0], target[1]) and an unsorted collection of half-open intervals intervals. Return true if the target conflicts with at least one interval. Otherwise, return false.
Two half-open intervals conflict when they share at least one point. Endpoints that only touch are not a conflict. Equivalently, [aStart, aEnd) and [bStart, bEnd) do not conflict when aEnd <= bStart or bEnd <= aStart.
This is a single query. The input does not need to be sorted.
Function
hasIntervalConflict(target: int[], intervals: int[][]) → booleanExamples
Example 1
target = [4,8]intervals = [[8,10],[1,4],[6,7]]return = trueThe intervals [1,4) and [8,10) only touch the target at an endpoint, but [6,7) shares points with [4,8).
Example 2
target = [4,8]intervals = [[10,12],[1,4],[8,10]]return = falseEvery interval is disjoint from the target. In particular, [1,4) ends when the target begins, and [8,10) begins when the target ends.
Constraints
target.length == 2.- Every row of
intervalshas length2. - Every target and collection interval is valid:
start < end. intervalsmay be empty and may appear in any order.