Count Empty Seats
This problem is based on a simple seat check, like looking at available spots in a small theater or shuttle bus. Each seat is shown as either occupied or empty.
In this version, the list uses 1 for an occupied seat and 0 for an empty seat. Your task is to count how many empty seats are left.
For example, if the seat list is [1,0,1,0,0], the answer is 3 because there are three zeros in the list.
So the task is to scan the seat statuses and count how many places are still open.
Example Input & Output
There are three empty seats in the row.
All seats are occupied, so none are empty.
With no seats in the list, the empty count stays 0.
Algorithm Flow

Solution Approach
A clean way to solve this is to use a counter.
Start by creating a variable like empty_count and set it to 0. That variable will store how many empty seats you have found so far.
Then go through the seat list one value at a time. Each time you see a seat status, check whether it is equal to 0.
The condition is:
If that condition is true, increase empty_count by 1.
After the loop finishes, the counter holds the total number of empty seats, so that is the final answer.
The logic is simple because every seat is checked in the same way: if it is empty, count it.
Best Answers
program count_empty_seats
dictionary
seats: array[1..100] of integer
empty_count, i, n: integer
algorithm
input(seats)
empty_count <- 0
n <- seats.length
for i <- 0 to n - 1 do
if seats[i] = 0 then
empty_count <- empty_count + 1
endif
endfor
output(empty_count)
endprogramComments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
