```
function findRightInterval(intervals) {
let n = intervals.length
for (let i = 0; i < n; i++) intervals[i].index = i
intervals.sort((i, j) => i.start - j.start)
function findRightIndex(target) {
let left = 0
let right = n
while (left < right) {
let mid = (left + right) >> 1
let val = intervals[mid].start
if (val < target) left = mid + 1
else right = mid
}
return intervals[left] ? intervals[left].index : -1
}
let ans = Array(n)
for (let interval of intervals) ans[interval.index] = findRightIndex(interval.end)
return ans
}
```