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.
CapacityLeft(capacity: int, partySizes: list<int>) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int CapacityLeft(int capacity, List<int> partySizes) {
}
Worked examples
| Call | Result |
|---|---|
CapacityLeft(100, new List<int> { 20, 25, 30 }) | 25 |
CapacityLeft(50, new List<int> { 10, 20, 25 }) | 0 |
CapacityLeft(100, new List<int> { 20, 25, 30, 15, 12 }) | 0 |
CapacityLeft(200, new List<int> { }) | 200 |
Hint
Sum the list, subtract from capacity, and floor at zero.
Reference solution in C#
public int CapacityLeft(int capacity, List<int> partySizes) {
int total = 0;
foreach (int s in partySizes) total += s;
return Math.Max(0, capacity - total);
}