Medium · Binary Search
Find Right Interval
Given an array intervals where intervals[i] = [start_i, end_i] and all starts are distinct, return an array whose i-th entry is the index j of the interval with the smallest start_j such that start_j ≥ end_i (j may equal i), or -1 if no such interval exists.
Examples
Example 1
[[3,4],[2,3],[1,2]] → [-1,0,1]Output: [-1, 0, 1]
Example 2
[[1,4],[2,3],[3,4]] → [-1,2,-1]Output: [-1, 2, -1]
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.