Booking Concert Tickets in Groups - Problem
Design a Concert Ticketing System
You're building a ticketing system for a popular concert venue! The concert hall has
Your system must handle two types of booking requests:
🎫 Group Seating (gather): A group of
🎫 Flexible Seating (scatter): A group of
The customers are picky though! They have these requirements:
• Only consider rows 0 through
• Always prefer the smallest row number available
• Within a row, prefer seats with smallest numbers
Your Task:
Implement
•
•
You're building a ticketing system for a popular concert venue! The concert hall has
n rows (numbered 0 to n-1) with m seats each (numbered 0 to m-1).Your system must handle two types of booking requests:
🎫 Group Seating (gather): A group of
k people want to sit together in the same row🎫 Flexible Seating (scatter): A group of
k people are okay sitting apart, just want seatsThe customers are picky though! They have these requirements:
• Only consider rows 0 through
maxRow• Always prefer the smallest row number available
• Within a row, prefer seats with smallest numbers
Your Task:
Implement
BookMyShow class with:•
gather(k, maxRow): Returns [row, seat] of first seat for k consecutive seats, or [] if impossible•
scatter(k, maxRow): Returns true if k seats can be allocated (anywhere), false otherwise Input & Output
example_1.py — Basic Operations
$
Input:
["BookMyShow", "gather", "gather", "scatter", "scatter"]
[[2, 5], [4, 0], [2, 0], [5, 1], [5, 1]]
›
Output:
[null, [0, 0], [], true, false]
💡 Note:
BookMyShow bms = new BookMyShow(2, 5); // 2 rows, 5 seats each
bms.gather(4, 0); → [0, 0] (4 seats in row 0, starting at seat 0)
bms.gather(2, 0); → [] (row 0 only has 1 seat left, can't fit 2 consecutive)
bms.scatter(5, 1); → true (can scatter 5 people across rows 0-1)
bms.scatter(5, 1); → false (not enough total seats remaining)
example_2.py — MaxRow Constraint
$
Input:
["BookMyShow", "gather", "gather", "gather"]
[[3, 4], [2, 1], [3, 2], [2, 2]]
›
Output:
[null, [0, 0], [1, 0], [2, 0]]
💡 Note:
BookMyShow bms = new BookMyShow(3, 4); // 3 rows, 4 seats each
bms.gather(2, 1); → [0, 0] (row 0 available, fits 2 consecutive seats)
bms.gather(3, 2); → [1, 0] (row 0 has only 2 seats left, use row 1)
bms.gather(2, 2); → [2, 0] (rows 0,1 don't have enough consecutive seats)
example_3.py — Scatter vs Gather
$
Input:
["BookMyShow", "scatter", "gather", "scatter"]
[[2, 3], [4, 1], [2, 1], [1, 1]]
›
Output:
[null, true, [], true]
💡 Note:
BookMyShow bms = new BookMyShow(2, 3); // 2 rows, 3 seats each
bms.scatter(4, 1); → true (scatter 4 people across rows 0-1: fills row 0 + 1 seat in row 1)
bms.gather(2, 1); → [] (no row has 2 consecutive seats after scattering)
bms.scatter(1, 1); → true (1 seat still available in row 1)
Constraints
- 1 ≤ n ≤ 5 × 104
- 1 ≤ m, k ≤ 109
- 0 ≤ maxRow ≤ n - 1
- At most 5 × 104 calls will be made to gather and scatter
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code