rooms: an entry [number, area] is a room with the unique number number and floor area area.
Guests book through guests: a request [want, need] means the guest wants a room numbered as close to want as possible, with an area of at least need. Among the rooms with area at least need, pick the one with the smallest |number - want|, breaking ties by the smaller number. If no room is large enough, the answer is -1.
Requests are independent: a room picked for one guest stays available to the others. Return the answers in request order.rooms=[[101, 20], [104, 35], [108, 15], [110, 40]], guests=[[105, 30], [109, 10], [107, 38], [100, 50]] → [104, 108, 110, -1]
For the first guest rooms 104 and 110 are big enough, and 104 is closer. For the second every room fits; 108 and 110 are both 1 away, so the smaller number, 108, wins. The third guest can only have 110. No room has an area of 50 or more, hence -1.
rooms=[[7, 5]], guests=[[1, 5], [7, 6]] → [7, -1]
The only room is big enough for the first guest however far it is, and too small for the second.
rooms=[[101, 20], [104, 35], [108, 15], [110, 40]], guests=[[105, 30], [109, 10], [107, 38], [100, 50]]
[104, 108, 110, -1]
Run checks the first 3 tests in your browser. Submit checks all 205 tests on the server, hidden ones included.