Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Consecutive Theater Seats

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Consecutive Theater Seats. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

The Zulily app needs to recommend the best available seating block for a live shopping theater event. Write a PostgreSQL query that finds one block of consecutive available seats for a specified screening.

Requirements

  1. Consider only screening 101 and seats whose status is available.
  2. Treat seats as consecutive only within the same row and seat rank, where rank 1 is the best rank.
  3. Select the block with the best rank first, then the greatest number of consecutive seats, then the earliest row and starting seat as deterministic tie-breakers.
  4. Return the screening name, row, rank, starting seat, ending seat, and block length.

Schema

screenings
ColumnTypeDescription
screening_idPKINTUnique screening identifier
screening_nameVARCHAR(100)Name of the Zulily event or show
seat_inventory
ColumnTypeDescription
seat_idPKINTUnique seat inventory identifier
screening_idINTReferences screenings.screening_id
row_labelVARCHAR(10)Theater row label
seat_numberINTNumeric position within the row
seat_rankINTSeat quality rank, with 1 as the best rank
statusVARCHAR(20)Seat availability status
Tablesscreeningsseat_inventory
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results