This question evaluates event-driven simulation and state-management skills, including handling customer lifecycle, capacity constraints, FIFO queuing behavior, and revenue aggregation.
A casino buffet has a maximum capacity capacity (number of customers that can be seated at once).
You are given:
prices
: an array where
prices[i]
is how much customer
i
is willing to pay.
events
: an array of customer IDs. For each customer
id
, the 1st time
id
appears means the customer arrives; the 2nd time means the customer leaves; the 3rd time arrives again; the 4th time leaves again; etc. (Arrivals and departures are interleaved across customers.)
Rules:
Return the total buffet revenue.
Example event interpretation:
events = [0, 1, 2, 0, 2]
means: 0 arrives → 1 arrives → 2 arrives → 0 leaves → 2 leaves.
Implement a function:
int capacity, int[] prices, int[] events
long totalRevenue