FastPrepMost Booked Origin-Destination Route

Most Booked Origin-Destination Route

Airbnb logoAirbnb● MediumFULLTIMEOA

Problem statement

Two tables describe users and their listing reservations:

  • users stores each user's home city in origin.
  • user_booking stores one row per reservation and the booked listing's city in destination.

Find the origin-destination route or routes with the largest number of bookings. Count reservation rows, return every route tied for the maximum, and order tied routes by origin and then destination, both ascending.

Return the columns origin, destination, and booking_count.

Table schema

MySQLPostgreSQLPandas

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.

users

Users and their home cities.

ColumnTypeNullableDescription
guest_idPKIntegerNoUnique user identifier.
originTextNoThe user's home city.

user_booking

Reservations made by users for listings in destination cities.

ColumnTypeNullableDescription
reservation_idPKIntegerNoUnique reservation identifier.
guest_idIntegerNoUser who made the reservation.
listing_idIntegerNoBooked listing identifier.
destinationTextNoCity of the booked listing.
ts_bookingTimestampNoTimestamp when the booking was made.
ds_bookingDateNoCalendar date of the booking.

Foreign key: guest_id → users(guest_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
originTextNo—
destinationTextNo—
booking_countIntegerNo—

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

Constraints

  • users.guest_id and user_booking.reservation_id are unique and non-null.
  • Every user_booking.guest_id references one row in users.
  • origin and destination are non-null city names.
  • The input tables may be empty.
  • Each reservation row contributes exactly one booking to its route.

More Airbnb problems

See Airbnb hiring insights