How much room is left
A venue has a maximum capacity and a list of party sizes arriving. Return how many more guests can still enter.
- Sum all party sizes and subtract from capacity.
- If the parties already fill or exceed the room the answer is zero, never negative.
- An empty party list means nobody arrived yet.
capacity_left(capacity: int, party_sizes: list<int>) → int
Where you start
def capacity_left(capacity: int, party_sizes: list[int]) -> int:
Worked examples
| Call | Result |
|---|---|
capacity_left(100, [20, 25, 30]) | 25 |
capacity_left(50, [10, 20, 25]) | 0 |
capacity_left(100, [20, 25, 30, 15, 12]) | 0 |
capacity_left(200, []) | 200 |
Hint
Sum the list, subtract from capacity, and floor at zero.
Reference solution in Python
def capacity_left(capacity: int, party_sizes: list[int]) -> int:
total = 0
for s in party_sizes:
total += s
return max(0, capacity - total)