class Solution {
public:
int binarySearch(vector<vector<int>>& intervals, int target){
int left = 0;
int right = intervals.size() - 1;
int mid;
// [[1,4], [2,3], [6,7]]
while(left <= right){
mid = left + (right - left) / 2;
if(target == intervals[mid][0]){
right = mid - 1;
} else if (target > intervals[mid][0]){
left = mid + 1;
} else {
right = mid - 1;
}
}
return left == intervals.size() ? -1 : intervals[left][2];
}
vector<int> findRightInterval(vector<vector<int>>& intervals) {
for(int i = 0; i < intervals.size(); i++){
intervals[i].push_back(i);
}
vector<vector<int>> base = intervals;
sort(intervals.begin(), intervals.end());
vector<int> result;
for(auto& interval : base){
result.push_back(binarySearch(intervals, interval[1]));
}
return result;
}
};