Javascript - finally got it fast enough
\n/**\n * @param {number[][]} rooms\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar closestRoom = function(rooms, queries) {\n    let minId = 1
```\n/**\n * @param {number[][]} rooms\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar closestRoom = function(rooms, queries) {\n    let minId = 10000001, maxId = 0;\n    let maxSize = 0;\n    rooms.forEach(r => {\n        minId = minId < r[0] ? minId : r[0];\n        maxId = maxId > r[0] ? maxId : r[0];\n        maxSize = maxSize > r[1] ? maxSize : r[1];\n    });\n    const sizes = new Int32Array(maxId - minId + 1);\n    rooms.forEach(r => {\n        sizes[r[0] - minId] = r[1];\n    });\n    const answers = queries.map(([id, size]) => {\n        if (size > maxSize) return -1;\n        if (id > maxId) id = maxId;\n        if (sizes[id - minId] >= size) return id;\n        let idd = id - minId - 1, idu = id - minId + 1, sizeLen = sizes.length;\n        while (true) {\n            if (idd >= 0) {\n                if (sizes[idd] >= size) return idd + minId;\n            }\n            if (idu <= sizeLen) {\n                if (sizes[idu] >= size) return idu + minId;\n            }\n            idd--;\n            idu++;\n        }\n    });\n    return answers;\n};\n```\n
[]