Java TreeSet
\npublic int[] closestRoom(int[][] rooms, int[][] queries) {\n        Arrays.sort(rooms, (a,b) -> b[1] - a[1]);\n        int m = queries.length;\n        int n 
```\npublic int[] closestRoom(int[][] rooms, int[][] queries) {\n        Arrays.sort(rooms, (a,b) -> b[1] - a[1]);\n        int m = queries.length;\n        int n = rooms.length;\n        int [][]query = new int[m][3];\n        for(int i=0;i<m;i++){\n            query[i][0] = queries[i][0];\n            query[i][1] = queries[i][1];\n            query[i][2] = i;\n        }\n        int []ans = new int[m];\n        Arrays.sort(query, (a,b) -> b[1] - a[1]);\n        TreeSet<Integer> ts = new TreeSet();\n        int j = 0;\n        for(int i=0;i<m;i++){\n            while(j < n && rooms[j][1] >= query[i][1]){\n                ts.add(rooms[j++][0]);\n            }\n            Integer floor = ts.floor(query[i][0]);\n            Integer ceil = ts.ceiling(query[i][0]);\n            if(floor == null && ceil == null){\n                ans[query[i][2]] = -1;\n            }else if(floor == null){\n                ans[query[i][2]] = ceil;\n            }else if(ceil == null){\n                ans[query[i][2]] = floor;\n            }else{\n                ans[query[i][2]] = ((ceil - query[i][0]) < (query[i][0] - floor) ? ceil : floor);\n            }\n        }\n        return ans;\n    }\n```
[]