Skip to content

Practice Booking Concert Tickets in Groups

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2286
LeetCode Problem

Booking Concert Tickets in Groups

Problem Statement

BookMyShow(n,m) starts with n rows of m empty seats. gather(k,maxRow) allocates k consecutive seats in one row at most maxRow, choosing the smallest row and then seat; return [row,startSeat] or [] on failure. scatter(k,maxRow) allocates k seats across eligible rows in increasing row/seat order and returns true, or false without mutation when insufficient. Practice approach: A segment tree stores maximum free seats per row for gather and total free seats for scatter. Since allocation always consumes each row's leftmost free seats, one count per row suffices. Check total capacity before scattering and skip exhausted rows.

Source: Booking Concert Tickets in Groups on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["BookMyShow","gather","gather","scatter","gather","scatter"]
[[2,4],[3,0],[2,0],[3,1],[2,1],[1,1]]
Output
[null,[0,0],[],true,[1,2],false]
Explanation

After three seats in row zero are taken, scatter fills its last seat and two in row one. gather takes the final two seats; no seat then remains.

Constraints

1 <= n <= 5 * 10^4
1 <= m, k <= 10^9
0 <= maxRow < n
At most 5 * 10^4 total calls.

Related LeetCode Problems

Practice more problems similar to Booking Concert Tickets in Groups.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.