full comented solution py3 ))
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    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n        ans = [0] * len(queries)\n        \n        # Sort queries to handle largest size queries first\n        q = deque(sorted([(size, room, i) for i, (room, size) in enumerate(queries)], key=lambda a: (-a[0], a[1], a[2])))\n\n        # Sort rooms by descending size\n        rooms = deque(sorted(rooms, key=lambda x: -x[1]))\n\n        # Current available room ids\n        cands = []\n        \n        while q:\n            size, room, i = q.popleft()\n            # Add room ids to candidates as long as the top of room size meets the requirements\n            while rooms and rooms[0][1] >= size:\n                bisect.insort(cands, rooms.popleft()[0])\n                    \n            # If no room size available, return -1\n            if not cands:\n                ans[i] = -1\n                \n            # Else use bisect to find optimal room ids\n            else:\n                loc = bisect.bisect_left(cands, room)\n                if loc == 0:\n                    ans[i] = cands[loc]\n                elif loc == len(cands):\n                    ans[i] = cands[-1]\n                else:\n                    ans[i] = cands[loc - 1] if room - cands[loc - 1] <= cands[loc] - room else cands[loc]\n        \n        return ans\n\n```
['Python3']