starts
to store intervals' start points as keys and their indices as values.intervals
and populate the TreeMap with the start point and index of each interval.result
to store the indices of the right intervals.intervals
, use the TreeMap's ceilingEntry
method to find the least key greater than or equal to the interval's end point.ceilingEntry
returns a non-null value, store the corresponding index in result
. Otherwise, store -1
to indicate no right interval exists.result
array.