Java - O(n*k) - Sort by Room size
\nclass Solution {\n    class NewRoom {\n        int index, id, size;\n        NewRoom(int id, int size) {\n            this.id = id;\n            this.size = s
```\nclass Solution {\n    class NewRoom {\n        int index, id, size;\n        NewRoom(int id, int size) {\n            this.id = id;\n            this.size = size;\n        }\n    }\n    \n    public int binSearch(NewRoom[] newRooms, int[] query) {\n        int preferred = query[0], minSize = query[1];\n        int left = 0, right = newRooms.length;\n        \n        while (left < right) {\n            int mid = left + (right - left) / 2;\n            \n            if (newRooms[mid].size >= minSize) {\n                if (mid-1 >= 0 && newRooms[mid-1].size >= minSize) right = mid;\n                else return mid;\n            } else {\n                left = mid + 1;\n            }\n        }\n        return left;\n    }\n\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n        int n = rooms.length, k = queries.length;\n        int[] soln = new int[k];\n        \n        NewRoom[] newRooms = new NewRoom[n];\n        for (int i=0; i<n; i++) {\n            newRooms[i] = new NewRoom(rooms[i][0], rooms[i][1]);\n        }\n        Arrays.sort(newRooms, (a, b) -> {\n            if (a.size < b.size) return -1;\n            else if (a.size == b.size) {\n                if (a.id <= b.id) return -1;\n                else return 1;\n            }\n            else return 1;\n        });\n        \n        int ct = 0;\n        for (int[] query : queries) {\n            int startIndex = binSearch(newRooms, query);\n            int minDiff = Integer.MAX_VALUE, minIndex = -1;\n            \n            for (int i=startIndex; i<n; i++) {\n                int newDiff = Math.abs(newRooms[i].id - query[0]);\n                if (newDiff < minDiff || (newDiff == minDiff && newRooms[i].id < newRooms[minIndex].id)) {\n                    minDiff = newDiff;\n                    minIndex = i;\n                }\n            }\n            \n            if (minIndex == -1) soln[ct++] = -1;\n            else soln[ct++] = newRooms[minIndex].id;\n        }\n        \n        \n        return soln;\n    }\n}\n```
[]