plaintext
function count_available_rooms(n, rooms)
// rooms is array of pairs (occupancy, capacity) count := 0
for each room in rooms
free_space := room.capacity - room.occupancy
if free_space >= 2 then
count := count + 1
return count
The loop processes each room once. For each pair, you compute the difference between capacity and occupancy. If that difference is at least , you increment the counter. The time complexity is where is the number of rooms. You check each room exactly once. The space complexity is if you process rooms as you read them.