Process Airline Seat Requests
Problem statement
An airline stores the current state of every seat and a sequence of reservation or purchase requests.
- A request with value
1reserves a free seat. - A request with value
2purchases a free seat. - A person may also purchase a seat that the same person previously reserved.
- Every other request is ignored.
Process requests from the smallest request_id to the largest and return the final state of every seat.
Table schema
MySQL
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
seats
| Column | Type | Nullable | Description |
|---|---|---|---|
| seat_noPK | Integer | No | Unique seat number. |
| status | Integer | No | 0 is free, 1 is reserved, and 2 is purchased. |
| person_id | Integer | No | 0 for a free seat; otherwise the reserving or purchasing person. |
requests
| Column | Type | Nullable | Description |
|---|---|---|---|
| request_idPK | Integer | No | Processing order. |
| request | Integer | No | 1 reserves and 2 purchases. |
| seat_no | Integer | No | — |
| person_id | Integer | No | — |
Foreign key: seat_no → seats(seat_no)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| seat_no | Integer | No | — |
| status | Integer | No | — |
| person_id | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Every
requests.seat_noappears inseats. - For this exercise, assume each
request_idis unique and return seats in ascendingseat_noorder.