C++20 sections · 1024 units
Open in Course

George - Algorithm

Count-as-you-go approach

Here's the plan:

1.1. Read nn (number of rooms).

2.2. Initialize count = 0.

3.3. For each of nn rooms, read occupancy and capacity.

4.4. If capacity - occupancy >= 2, increment count.

5.5. Print count. This is the filtering pattern. You stream items and count how many pass your test. Don't store items or remember decisions. Just maintain a running count. Each room passes or fails, update counter so. Notice you process data as you read it. Memory stays constant regardless of nn. Check 10 rooms or 100000 rooms, you only need one counter.