Sorting queries, and rooms and using TreeSet in JAVA
\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n       Arrays.sort(rooms, (a, b) -> -1*(a[1] - b[1]));\n        HashMap<Stri
```\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n       Arrays.sort(rooms, (a, b) -> -1*(a[1] - b[1]));\n        HashMap<String, Integer> hash = new HashMap<>();\n        int[][] pro = new int[queries.length][2];\n        for (int i = 0; i < queries.length; i++){pro[i] = new int[]{queries[i][0], queries[i][1]};}\n        Arrays.sort(pro, (a, b) -> -1*(a[1]- b[1]));\n       for (int i = 0; i < queries.length; i++){\n        System.out.print(Arrays.toString(queries[i]) + " ");\n       }\n        System.out.println("");\n        for (int i = 0; i < queries.length; i++){\n        System.out.print(Arrays.toString(pro[i]) + " ");\n       }\n        TreeSet<Integer> set = new TreeSet<>();\n        int counter = 0; \n        for (int[] tt: pro){\n            while (counter < rooms.length && rooms[counter][1] >= tt[1]){\n                set.add(rooms[counter][0]);\n                counter += 1;\n            }        \n            Integer k1 = set.floor(tt[0]); Integer k2 = set.higher(tt[0]);\n            \n            if (k1 == null && k2 == null){\n                hash.put(tt[0] + "_" + tt[1], -1);\n            }\n            else if (k1== null){\n                hash.put(tt[0] + "_" + tt[1], k2);\n            }\n            else if (k2 == null) {\n                hash.put(tt[0] + "_" + tt[1], k1);\n            }\n            \n            else if (tt[0] - k1 > k2 - tt[0]){\n            hash.put(tt[0] + "_" + tt[1], k2);\n                }\n            \n            else {\n                hash.put(tt[0] + "_" + tt[1], k1);\n            }\n        }\n        System.out.println(hash);\n        int[] ans = new int[queries.length];\n        for (int i = 0; i < queries.length; i++){\n            String uu = queries[i][0] + "_" + queries[i][1];\n            ans[i] = hash.get(uu);\n        }\n        return ans;\n    }\n}\n```
[]