JAVA | Sort + Greedy
\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n\n       Arrays.sort(rooms, (room1, room2) -> room1[1] == room2[1] ? room1[0
```\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n\n       Arrays.sort(rooms, (room1, room2) -> room1[1] == room2[1] ? room1[0]-room2[0] : room2[1]-room1[1]);\n        int res[] = new int[queries.length];\n        \n        for(int i=0; i<queries.length; i++){\n            int tempRes = -1;\n            for(int j=0; j<rooms.length; j++){\n\t\t\t\n                if(rooms[j][1] >= queries[i][1]){\n                    if(tempRes == -1){\n                        tempRes = j;\n                    }else{\n\t\t\t\t\t\n                       if( Math.abs(rooms[tempRes][0] - queries[i][0]) > Math.abs(rooms[j][0] - queries[i][0]) ){\n                           tempRes = j;\n                       }else if (Math.abs(rooms[tempRes][0] - queries[i][0]) == Math.abs(rooms[j][0] - queries[i][0]) && \n                                 rooms[tempRes][0] >  rooms[j][0]){\n                          temp = j;\n                       }\n                    }\n                }else{\n                    break;\n                }\n            }\n     res[i] = tempRes == -1 ? -1 : rooms[tempRes][0];\n\n        }\n        \n        return res;\n    }\n}\n```
[]