FunctionRacerProblemsRace

Theater Seats and Group Bookings

MediumClassesPython, JavaScript, TypeScript, Java, C++

Implement a class SeatMap for a small theater with rows rows of seats seats each. Rows are numbered from 0 at the front and seats from 0 at the left end of each row. Write these methods:

Every row, seat and size passed in is valid: 0 <= row < rows, 0 <= seat < seats and 1 <= size <= seats. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

SeatMap(2, 4)
book_seat(0, 1) returns true
book_group(2) returns [0,2]
book_group(2) returns [1,0]
book_seat(1, 0) returns false
free_in_row(0) returns 1
cancel_seat(0, 1) returns true
book_group(2) returns [0,0]
book_group(3) returns [-1,-1]

Seat 1 of row 0 is taken, so the first pair goes to seats 2 and 3 of row 0. Row 0 then has only seat 0 free, so the next pair goes to the front of row 1. Cancelling seat 1 of row 0 makes room for a pair at seats 0 and 1. No row has three free seats together.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems