Loading...
Loading...
A cinema has s seats, numbered from 1, all AVAILABLE at first. enum Action { SELECT, PAY, TIMEOUT } and enum SeatStatus { AVAILABLE, LOCKED, BOOKED } with SeatStatus on(Action a): AVAILABLE + SELECT → LOCKED; LOCKED + PAY → BOOKED; LOCKED + TIMEOUT → AVAILABLE. Every other pair is not allowed, and on returns the same status.
Commands come from a phone app, so the action may be in any case and may be misspelt.
Seat n: OLD -> NEW. A pair that is not allowed: Seat n: ACTION not allowed while STATUS. A bad action: Seat n: unknown action WORD. Last line: Booked: k of s.Example
Input
3 6 1 select 2 PAY 1 pay 3 Select 3 timeout 2 book
Output
Seat 1: AVAILABLE -> LOCKED Seat 2: PAY not allowed while AVAILABLE Seat 1: LOCKED -> BOOKED Seat 3: AVAILABLE -> LOCKED Seat 3: LOCKED -> AVAILABLE Seat 2: unknown action book Booked: 1 of 3
Seat 2 cannot be paid for before it is selected; book is not an action.
Try the problem first. Open one hint at a time.
Keep SeatStatus[] seats = new SeatStatus[s + 1]; and fill it with AVAILABLE.
In on(), switch on this; for LOCKED, switch again on a.
If on() returns the same status, the move was not allowed.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor