Code Logo

Count Empty Seats

Published at19 Apr 2026
Loops & Iteration Easy 0 views
Like0

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.

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
seats = [1,0,1,0,0]
Output
3
Explanation

There are three empty seats in the row.

Example 2
Input
seats = [1,1,1]
Output
0
Explanation

All seats are occupied, so none are empty.

Example 3
Input
seats = []
Output
0
Explanation

With no seats in the list, the empty count stays 0.

Algorithm Flow

Recommendation Algorithm Flow for Count Empty Seats
Recommendation Algorithm Flow for Count Empty Seats

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:

seats[i] = 0

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

Pseudocode - Approach 1
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)
endprogram