Theater Seats and Group Bookings
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:
SeatMap(rows, seats)starts with every seat free.book_seat(row, seat)books one seat. Returnstrueif it was free, orfalseif it was already booked (then nothing changes).cancel_seat(row, seat)frees a booked seat and returnstrue, or returnsfalseif that seat was not booked.book_group(size)bookssizefree seats side by side in one row for a group. It uses the frontmost row that hassizefree seats next to each other, and in that row the leftmost such block. Returns[row, first], wherefirstis the leftmost seat of the block, or[-1, -1]if no row has room (then nothing is booked).free_in_row(row)returns how many seats inroware free.
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
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
1 <= rows <= 5and1 <= seats <= 8- Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.