Code Logo

Check Bus Seat Available

Published at19 Apr 2026
Logic & Conditionals Easy 8 views
Like0

Given the total number of seats on a bus and the number of passengers already seated, determine whether there is at least one seat available. Return true if there are empty seats, false if the bus is full or has no seats.

For example, a bus with 50 seats and 30 passengers has 20 seats available — return true. With 50 seats and 50 passengers, the bus is full — return false. A bus with 0 seats returns false.

This problem teaches the concept of capacity checking — comparing current usage against total capacity. This pattern is used in booking systems, inventory management, and resource allocation.

The solution checks if the number of passengers is less than the total seats. If passengers < seats, there is at least one empty seat and the result is true. Otherwise, the bus is full or has no seats and the result is false.

Edge cases include zero seats (return false even with zero passengers), a completely empty bus (return true if seats > 0), and a bus at exactly full capacity (return false).

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
total = 40, taken = 36
Output
AVAILABLE
Explanation

There are still seats left, so the bus is not full yet.

Example 2
Input
total = 40, taken = 40
Output
FULL
Explanation

Every seat is already taken.

Example 3
Input
total = 12, taken = 0
Output
AVAILABLE
Explanation

If nobody has taken a seat yet, seats are still available.

Algorithm Flow

Recommendation Algorithm Flow for Check Bus Seat Available
Recommendation Algorithm Flow for Check Bus Seat Available

Solution Approach

Compare the number of passengers to the total seat capacity using the less-than operator.

function hasAvailableSeats(totalSeats, passengers)
  return passengers < totalSeats

Return the result of passengers < totalSeats. This evaluates to true when the number of seated passengers is strictly less than the total seats available, meaning at least one seat is empty. It returns false when the bus is full (passengers == seats) or has no seats at all.

Time complexity is O(1), space complexity is O(1).

Best Answers

Pseudocode - Approach 1
program check_bus_seat_available
dictionary
   total, taken: integer
algorithm
   input(total, taken)
   if taken < total then
      output("AVAILABLE")
   else
      output("FULL")
   endif
endprogram