C++ | Sorting + Binary Search
\nclass Solution {\npublic:\n    bool static cmp(vector<int>&a,vector<int>&b)\n    {\n        return a[1]>b[1];\n    }\n    vector<int> closestRoom(vector<vecto
```\nclass Solution {\npublic:\n    bool static cmp(vector<int>&a,vector<int>&b)\n    {\n        return a[1]>b[1];\n    }\n    vector<int> closestRoom(vector<vector<int>>& rooms,vector<vector<int>>& queries)\n    {\n        int i=0;\n        for(auto &q:queries)\n            q.push_back(i++);\n        vector<int>res(i,-1);\n        sort(rooms.begin(),rooms.end(),cmp);\n        sort(queries.begin(),queries.end(),cmp);\n        i=0;\n        set<int>s;\n        for(auto &q:queries)\n        {\n            while(i<rooms.size() && q[1]<=rooms[i][1])\n            {\n                s.insert(rooms[i][0]);\n                i++;\n            }\n            if(!s.empty())\n            {\n                auto it=s.lower_bound(q[0]);\n                int p1=INT_MAX,p2=INT_MAX;\n                if(it!=s.begin())\n                    p1=*prev(it);\n                if(it!=s.end())\n                    p2=*it;\n                res[q[2]]=abs(q[0]-p1)<=abs(q[0]-p2)?p1:p2;\n            }\n        }\n        return res;\n    }\n};\n```
[]