Java Simple and easy T O(n log n), S O(n) solution, clean code with comments
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\n\n\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n        \n        int numRo
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n\n\n```\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n        \n        int numRoom = rooms.length;\n        int numQuery = queries.length;\n        \n        \n        for(int i = 0; i < numQuery; i++){\n\t\t\t//append index\n            queries[i] = new int[]{queries[i][0], queries[i][1], i};\n        }\n        \n        //sort the roos and queries in increasing order of room size\n        Arrays.sort(rooms, (a, b) -> (a[1] != b[1] ? (a[1] - b[1]) : (a[0] - b[0])));\n        Arrays.sort(queries, (a, b) -> (a[1] != b[1] ? (a[1] - b[1]) : (a[0] - b[0])));\n        \n        TreeSet<Integer> roomIds = new TreeSet();\n        int[] result = new int[numQuery];\n        \n        int j = numRoom - 1;\n        for(int i = numQuery - 1; i >= 0; i--){\n            \n            int currRoomId = queries[i][0];\n            int currRoomSize = queries[i][1];\n            int currQueryIndex = queries[i][2];\n            \n            //add all the which size is greater or equal than query room size\n            while(j >= 0 && rooms[j][1] >= currRoomSize){\n                roomIds.add(rooms[j--][0]);\n            }\n            \n            //found room with sufficient size,\n            if(roomIds.contains(currRoomId)){\n                //directly add this room\n                result[currQueryIndex] = currRoomId;\n                continue;\n            }\n            \n            //next room which is just greater that current roomId\n            Integer nextRoomId = roomIds.higher(currRoomId);\n            \n            //previous roomId which is just smaller than current roomId\n            Integer prevRoomId = roomIds.lower(currRoomId);\n            \n            if(nextRoomId == null && prevRoomId == null){\n                //no nearest roomId \n                result[currQueryIndex] = -1;\n                \n            }else if(nextRoomId == null){\n                \n                result[currQueryIndex] = prevRoomId;\n                \n            }else if(prevRoomId == null){\n                \n                result[currQueryIndex] = nextRoomId;\n                \n            }else if(nextRoomId != null && prevRoomId != null){\n                //get the nearest roomId\n                if((currRoomId - prevRoomId) <= (nextRoomId - currRoomId)){\n                    result[currQueryIndex] = prevRoomId;\n                }else{\n                    result[currQueryIndex] = nextRoomId;\n                }\n            }\n            \n        }\n        \n        return result;\n    }\n}\n```
['Java']