Simple python3 solution | 1636 ms - faster than 86.84% solutions
Complexity\n- Time complexity: O(n \cdot \log(n) + k \cdot \log(k) + (k + n) \cdot \log(n)) = \n= O(n\cdot\log(n) + k\cdot\log(max(k, n)))\n Add your time compl
# Complexity\n- Time complexity: $$O(n \\cdot \\log(n) + k \\cdot \\log(k) + (k + n) \\cdot \\log(n)) = $$\n$$= O(n\\cdot\\log(n) + k\\cdot\\log(max(k, n)))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n + k)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\nwhere `n == rooms.length <= 10^5` and `k == queries.length <= 10^4`\n\nLet $$m = max(n, k)$$, then:\n- Time complexity: $$O(m \\cdot \\log(m))$$\n\n- Space complexity: $$O(m)$$\n\n# Code\n``` python3 []\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n        rooms.sort(key=lambda x: x[1])\n\n        sorted_queries = sorted(\n            (min_size, pref, i)\n            for i, (pref, min_size) in enumerate(queries)\n        )\n\n        def get_room_id(sl, preferred):\n            if len(sl) == 0:\n                return -1\n\n            index = sl.bisect_left(pref)\n            if index == len(sl):\n                return sl[-1]\n            \n            right = sl[index]\n            if index != 0:\n                left = sl[index - 1]\n                if abs(left - preferred) <= abs(right - preferred):\n                    return left\n            return right\n\n        sl = SortedList()\n        j = len(rooms) - 1\n        result = {}\n\n        for min_size, pref, i in reversed(sorted_queries):\n            while j >= 0 and rooms[j][1] >= min_size:\n                sl.add(rooms[j][0])\n                j -= 1\n                \n            result[i] = get_room_id(sl, pref)\n        \n        return [j for _, j in sorted(result.items())]\n```
['Two Pointers', 'Binary Search', 'Sorting', 'Python3']