java, sorting(rooms, queries), binarySearch(make possible room list, find closest room)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] closestRoom(int[][] rooms, int[][] queries) {\n\n        // 1. rooms \uB97C size\uAC00 \uD070 \uC21C\uC73C\uB85C \uC815\uB82C\uD55C\uB2E4. \n        \n        // 2. queries\uB97C origin idx\uB97C \uD3EC\uD568\uD55C queriesWithIdx \uB85C \uBCC0\uD615\uD558\uACE0 (queriesWithIdx[][2] \uC5D0 origin Idx \uC800\uC7A5)\n        //    minSize\uAC00 \uD070 \uC21C\uC73C\uB85C \uC815\uB82C\uD55C\uB2E4. \n        \n        // 3. \uC815\uB82C\uB41C queriesWithIdx \uB97C \uC21C\uD68C\uD558\uBA74\uC11C \n        //    rooms\uC758 size \uAC00 queriesWithIdx[i][1] ( minSize) \uBCF4\uB2E4 \uD06C\uAC70\uB098 \uAC19\uC740 \uAC83\uB4E4\uB9CC  List<int[]> roomList \uC5D0 \uCD94\uAC00\uD55C\uB2E4.\n        //    \u203B  List<int[]> roomList\uB294 roomId \uC21C\uC73C\uB85C \uC815\uB82C\uB418\uC5B4\uC57C\uD558\uACE0 \uC774\uC5D0 \uB9DE\uAC8C \n        //        binarySearchUpper\uB85C roomList\uC5D0\uC11C roomId\uC758 \uC704\uCE58\uB97C \uCC3E\uC740 \uD6C4 \uD574\uB2F9 \uC704\uCE58\uC5D0 \uC0BD\uC785\uD574\uC900\uB2E4. \n\n        // 4. 3\uBC88\uC758 \uACFC\uC815\uC774 \uB05D\uB0AC\uC73C\uBA74 roomList \uC5D0\uB294 queriesWithIdx[i] \uAC00 \uAC08 \uC218 \uC788\uB294 room\uB4E4\uB9CC \uC800\uC7A5\uB418\uC5B4\uC788\uACE0 \n        //    binarySearchUpper\uB85C queriesWithIdx[i][0](preferrred) \uB97C \uCC3E\uC740 \uD6C4 \n        //     \uCC3E\uC740 index, \uCC3E\uC740index-1, \uCC3E\uC740index+1 \uC911 \uAC00\uC7A5 \uAC00\uAE4C\uC6B4 \uACF3\uC73C\uB85C \uBC30\uC815\uD574\uC8FC\uBA74\uB41C\uB2E4.\n        //     result[queriesWithIdx[i][2]] \uC5D0 \uC800\uC7A5 \n        //     \u203B  2. \uC5D0\uC11C queriesWithIdx \uAC00  minSize \uD070 \uC21C\uC73C\uB85C \uC815\uB82C \uB418\uC5C8\uAE30 \uB54C\uBB38\uC5D0 originIdx\uB97C \uC774\uC6A9\uD574 \uB123\uC5B4\uC918\uC57C\uD55C\uB2E4. \n\n        // 5. result \uBC18\uD658\n\n\n        int queriesWithIdx[][] = new int[queries.length][3];\n        for(int i = 0; i < queries.length; i++) {\n            queriesWithIdx[i][0] = queries[i][0];\n            queriesWithIdx[i][1] = queries[i][1];\n            queriesWithIdx[i][2] = i;\n        }\n\n        Arrays.sort(queriesWithIdx, new Comparator<int[]>() {\n\n            @Override\n            public int compare(int[] arg0, int[] arg1) {\n                return arg1[1]-arg0[1];\n            }\n            \n        });\n\n\n        Arrays.sort(rooms, new Comparator<int[]>() {\n\n            @Override\n            public int compare(int[] arg0, int[] arg1) {\n                return arg1[1] - arg0[1];\n            }\n            \n        });\n\n        // for(int i = 0; i < rooms.length; i++) System.out.print("[" + rooms[i][0] + " " + rooms[i][1] + "] "); System.out.println();\n        \n        int result[] = new int[queries.length];\n\n        List<int[]> roomList = new ArrayList<int[]>();\n        int roomIdx = 0;\n        \n\n        for(int i = 0; i < queriesWithIdx.length; i++) {\n            int preferred = queriesWithIdx[i][0];\n            int minSize = queriesWithIdx[i][1];\n\n            while(roomIdx < rooms.length  && rooms[roomIdx][1] >= minSize) {\n                int idx = binarySearchUpper(roomList, rooms[roomIdx][0]) ;\n                roomList.add(idx, new int[]{rooms[roomIdx][0], rooms[roomIdx][1]});\n                roomIdx++;\n            }   \n\n            if ( roomList.size() == 0) {\n                result[queriesWithIdx[i][2]] = -1;\n                continue;\n            }\n            \n            int idx = binarySearchUpper(roomList, preferred);\n            if ( idx == roomList.size()) idx--;\n\n            if ( roomList.get(idx)[0] == preferred  ) {\n                if (roomList.get(idx)[1] >= minSize) {\n                    result[queriesWithIdx[i][2]] = preferred;\n                    continue;\n                }  \n            }\n\n\n            int left = idx-1;\n            int right = idx+1;\n\n            int leftDist = Integer.MAX_VALUE;\n            int leftRoomId = -1;\n            int rightDist = Integer.MAX_VALUE;\n            int rightRoomId = -1;\n\n            if ( left >= 0 ) {\n                if ( roomList.get(left)[1] >= minSize ) {\n                    leftRoomId = roomList.get(left)[0];\n                    leftDist = preferred - leftRoomId;\n                }\n            }\n\n            if(right < roomList.size()) {\n                if ( roomList.get(right)[1] >= minSize ) {\n                    rightRoomId = roomList.get(right)[0] ;\n                    rightDist = rightRoomId - preferred;\n                }\n            }\n\n            if ( leftDist <= rightDist ) {\n                if ( leftDist > Math.abs(roomList.get(idx)[0]-preferred) && roomList.get(idx)[1] >= minSize ) {\n                    result[queriesWithIdx[i][2]] = roomList.get(idx)[0];\n                } else{\n                    result[queriesWithIdx[i][2]] = leftRoomId;\n                }\n                \n            } else{\n\n                if ( rightDist >= Math.abs(roomList.get(idx)[0]-preferred) && roomList.get(idx)[1] >= minSize  ) {\n                    result[queriesWithIdx[i][2]] = roomList.get(idx)[0];\n                } else{\n                    result[queriesWithIdx[i][2]] = rightRoomId;\n                }\n                \n            }\n            \n            \n        }\n\n        // for(int i = 0; i < result.length; i++) System.out.print(result[i] + " "); System.out.println();\n\n\n        return result;\n\n    }\n\n\n    private int binarySearchUpper(List<int[]> list, int target) {\n        int start = 0;\n        int end = list.size();\n        int mid;\n\n        while( start < end) {\n            mid = (start + end)/2;\n\n            if ( list.get(mid)[0] >= target) {\n                end = mid;\n            } else{\n                start = mid+1;\n            }\n        }\n\n        return end;\n    }\n}\n```
['Binary Search', 'Sorting', 'Java']