C++, Sorting queries and rooms by their sizes, and using ordered set for id
The code is self explanatory. Let me know if there are any doubts\n\n\nclass Solution {\npublic:\n    \n    static bool cmp(vector<int> &a , vector<int> & b){\n
**The code is self explanatory. Let me know if there are any doubts**\n\n```\nclass Solution {\npublic:\n    \n    static bool cmp(vector<int> &a , vector<int> & b){\n        return a[1] < b[1]; \n    }\n    \n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& q) {\n        vector<vector<int>> queries; \n        for(int i=0; i<q.size(); i++) {\n            queries.push_back({q[i][0], q[i][1], i}); \n        }\n        sort(queries.begin(), queries.end(), cmp); \n        sort(rooms.begin(), rooms.end(), cmp); \n        set<int> st; \n        for(auto x:rooms) st.insert(x[0]); \n        \n        vector<int > res(queries.size(), -1); \n        int i=0 , n = rooms.size(); \n        for(auto query:queries){\n            while(i<n && rooms[i][1] < query[1]) st.erase(rooms[i][0]), i++; \n            auto idx = st.lower_bound(query[0]); \n            if(st.size() == 0) break; \n            int curr = INT_MAX, prev; \n            if(idx != st.end()){\n                curr = abs(query[0] - (*idx)), prev = *idx; \n            }\n            \n            if(idx != st.begin()){\n                idx --; \n                if(curr > abs(query[0] -(*idx))) res[query[2]] = (*idx); \n                else if(curr == abs(query[0]- (*idx))) res[query[2]] = min(prev, *idx); \n                else res[query[2]] = (prev); \n            }\n            else res[query[2]] = (prev); \n        }\n        return res ; \n    }\n};\n```
['C', 'Sorting']