C++
\nclass Solution {\nprivate:\n    static bool cmp(vector<int>&a, vector<int>&b){\n        return a[1] > b[1] ;\n    }\npublic:\n    vector<int> closestRoom(vect
```\nclass Solution {\nprivate:\n    static bool cmp(vector<int>&a, vector<int>&b){\n        return a[1] > b[1] ;\n    }\npublic:\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        for(int i = 0; i < queries.size(); i++)\n            queries[i].push_back(i) ;  //add index\n        sort(queries.begin(), queries.end(), cmp) ;\n        sort(rooms.begin(), rooms.end(), cmp) ;\n        \n        vector<int>rets(queries.size()) ;\n        set<int>Set ;  // size is big enough room\n        int idx = 0 ;\n        for(auto& q : queries){\n            while(idx < rooms.size() && rooms[idx][1] >= q[1]){\n                Set.insert(rooms[idx][0]) ;\n                idx++ ;\n            }\n            int ans = -1 ;\n            int diff = INT_MAX ;\n            auto iter = Set.lower_bound(q[0]) ;\n            if(iter != Set.end()){\n                ans = *iter ;\n                diff = *iter - q[0] ;\n            }\n            if(iter != Set.begin()){\n                iter = prev(iter) ;\n                if(q[0] - *iter <= diff)\n                    ans = *iter ;\n            }\n            rets[q[2]] = ans ;\n        }\n        return rets ;\n    }\n};\n```
['Sorting']