FastPrepProcess Airline Seat Requests

Process Airline Seat Requests

Agoda logoAgoda● MediumFULLTIMEOA

Problem statement

An airline stores the current state of every seat and a sequence of reservation or purchase requests.

  • A request with value 1 reserves a free seat.
  • A request with value 2 purchases 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

ColumnTypeNullableDescription
seat_noPKIntegerNoUnique seat number.
statusIntegerNo0 is free, 1 is reserved, and 2 is purchased.
person_idIntegerNo0 for a free seat; otherwise the reserving or purchasing person.

requests

ColumnTypeNullableDescription
request_idPKIntegerNoProcessing order.
requestIntegerNo1 reserves and 2 purchases.
seat_noIntegerNo—
person_idIntegerNo—

Foreign key: seat_no → seats(seat_no)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
seat_noIntegerNo—
statusIntegerNo—
person_idIntegerNo—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Every requests.seat_no appears in seats.
  • For this exercise, assume each request_id is unique and return seats in ascending seat_no order.

More Agoda problems

See Agoda hiring insights