Drill

ProblemsPython › events

How much room is left

easyeventsPython

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

capacity_left(capacity: int, party_sizes: list<int>) → int

Solve it in the editor →

Where you start

def capacity_left(capacity: int, party_sizes: list[int]) -> int:
    

Worked examples

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

The same problem in another language

More events problems in Python