Treeset solution
sort  queries and rooms by size, then put all viable options into treeset, compare dis of preferred location to floor and to ceiling.\n\nclass Solution {\n    p
sort  queries and rooms by size, then put all viable options into treeset, compare dis of preferred location to floor and to ceiling.\n```\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n        Arrays.sort(rooms,(a,b) -> b[1] - a[1]);\n        int n = queries.length, m = rooms.length, qs[][] = new int[n][3], res[] = new int[n];\n        TreeSet<Integer> pq = new TreeSet<>();\n        \n        for (int i = 0; i < n; i++){\n            qs[i][0] = queries[i][0];\n            qs[i][1] = queries[i][1];\n            qs[i][2] = i;\n        }\n        \n        Arrays.sort(qs,(a,b)->b[1] - a[1]);\n        \n        for (int i = 0, j = 0; i < n; i++){\n            int size = qs[i][1], idx = qs[i][2], pre = qs[i][0];\n            \n            while (j < m && rooms[j][1] >= size){\n                pq.add(rooms[j++][0]);\n            }\n            \n            Integer floor = pq.floor(pre), ceiling = pq.ceiling(pre);\n            if (floor == null && ceiling == null){\n                res[idx] = -1;\n            }else if (floor == null){\n                res[idx] = ceiling;\n            }else if (ceiling == null){\n                res[idx] = floor;\n            }else{\n                res[idx] = ceiling - pre < pre - floor?ceiling:floor;\n            }\n        }\n        return res;\n    }\n}\n```
[]