C++20 sections · 1024 units
Open in Course

George - Implementation

Complete solution


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 22, you increment the counter. The time complexity is O(n)O(n) where nn is the number of rooms. You check each room exactly once. The space complexity is O(1)O(1) if you process rooms as you read them.