Easy C++ solution using set.
Sort queries and rooms by room size, largest first.\nFor the largest query, insert all rooms <= largest query into a set.\nThese rooms will be common for this q
Sort queries and rooms by room size, largest first.\nFor the largest query, insert all rooms <= largest query into a set.\nThese rooms will be common for this query as well as all the queries later in the array with smaller room size.\n\n```\nvector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        int idx = 0;\n        for (auto& q : queries) q.push_back(idx++);\n\n        auto f = [&](const vector<int>& a, const vector<int>& b) { return a[1] > b[1]; };\n        sort(rooms.begin(), rooms.end(), f);\n        sort(queries.begin(), queries.end(), f);\n        \n        set<int> cans;\n        vector<int> result(queries.size());\n        idx = 0; // for rooms now\n        for (auto& q : queries) {\n            while (idx < rooms.size() && q[1] <= rooms[idx][1]) cans.insert(rooms[idx++][0]);\n            if (cans.size() == 0) result[q[2]] = -1;\n            else {\n                auto it = cans.upper_bound(q[0]);\n                int r = 20000001;\n                if (it != cans.end()) r = *it;\n                if (it != cans.begin()) {\n                    --it;\n                    if (q[0] - *it <= r - q[0]) r = *it;\n                }\n                result[q[2]] = r;\n            }\n        }\n        return result;\n    }\n```
[]