Cheapest Block of Adjacent Available Seats in a Row
Last updated: November 29, 2026
Quick Overview
Given the per-seat prices of one row and a flag for whether each seat is still available, return the start index and total price of the cheapest run of exactly k adjacent available seats, or None if no such run exists.
StubHub
November 29, 20260
0
0 solved
Given the per-seat prices of one row and a flag for whether each seat is still available, return the start index and total price of the cheapest run of exactly k adjacent available seats, or None if no such run exists.
Buyers on StubHub usually want to sit together, so the seat map has to answer 'show me k seats side by side' quickly for every row in a section. A phone screen uses this to check that a candidate can write a clean sliding window that resets on sold seats instead of reaching for nested loops.
What the Interviewer Expects
- Clarifies that seats must be contiguous and all available
- Uses a fixed-size sliding window with an O(1) update per seat
- Resets the window correctly when an unavailable seat breaks the run
- Defines a tie-break (leftmost start) and states it
- Returns None cleanly when no run of length k exists
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the cheapest block across every row of a section?
- What changes if aisle seats count as breaking adjacency even when both are free?
- How would you support a buyer who accepts k seats split across two adjacent rows, aligned by seat number?
- Prices change every few seconds. How would you avoid recomputing every row on each update?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: prices (list of ints, cents or dollars), available (list of bools, same length), and k >= 1. Output: (start, total) for the cheapest window of k consecutive seats that are all available...
High-Level Design
Walk the row once, keeping the length of the current streak of available seats and the sum of its last k prices. When a seat is unavailable, reset both. Once the streak is at least k long, the window ...