Drill

ProblemsJavaScript › events

How much room is left

easyeventsJavaScript

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

Solve it in the editor →

Where you start

function capacityLeft(capacity, partySizes) {
  
}

Worked examples

CallResult
capacityLeft(100, [20,25,30])25
capacityLeft(50, [10,20,25])0
capacityLeft(100, [20,25,30,15,12])0
capacityLeft(200, [])200

Hint

Sum the list, subtract from capacity, and floor at zero.

Reference solution in JavaScript
function capacityLeft(capacity, partySizes) {
  let total = 0;
  for (const s of partySizes) total += s;
  return Math.max(0, capacity - total);
}

The same problem in another language

More events problems in JavaScript