Drill

ProblemsC# › events

How much room is left

easyeventsArraysMathC#

A venue has a maximum capacity and a list of party sizes arriving. Return how many more guests can still enter.

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.

Solve it in Python →

Where you start

public int CapacityLeft(int capacity, List<int> partySizes) {
    
}

Worked examples

CallResult
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);
}

The same problem in another language

More events problems in C#