Drill

ProblemsGo › events

How much room is left

easyeventsArraysMathGo

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

Go 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

func capacityLeft(capacity int, partySizes []int) int {
	
}

Worked examples

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

Hint

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

Reference solution in Go
func capacityLeft(capacity int, partySizes []int) int {
	total := 0
	for _, s := range partySizes {
		total += s
	}
	if capacity > total {
		return capacity - total
	}
	return 0
}

The same problem in another language

More events problems in Go