Test the Last Available Seat
Scenario
The room accepts bookings only when freeSeats is greater than zero.
Try it yourself
Choose a seat count and predict the decision before opening the result.
| Case | Result |
|---|---|
| 0 free seats | Select a choice above to see what happens. |
| 1 free seat | Select a choice above to see what happens. |
| 2 free seats | Select a choice above to see what happens. |
Reveal the explanation
- 0 free seats
Declined. The room is full.
- 1 free seat
Accepted. The last seat may be booked.
- 2 free seats
Accepted. The booking leaves room for another seat.
A check using >= 0 would overbook a full room. Keep both 0 and 1 in the test set.
Download shared test cases
Your turn
Write the expected result for 0, 1, and 2 free seats before you run the checker.
Common mistake Using a comparison that admits a booking when the room is full.
Check your work
The expected results are false, true, and true.
This browser could not save your progress. Changes last until you leave the page.