Compute Buffet Revenue with Waiting Guests and Repeat Visits
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Simulate buffet seating, FIFO waiting, early departures, and repeat visits while charging each guest at most once per day.
Constraints
- 0 <= nb_seats <= 100
- 1 <= len(paying_guests) <= 10
- Each payment is an integer from 0 through 1000000
- 2 <= len(guest_movements) <= 26
- Every movement is a valid guest identifier: 0 <= guest_movements[i] < len(paying_guests)
- Occurrences of a guest alternate arrival, departure, arrival, ...; a guest never has two active visits at once
- All visits are closed by the end of the movement sequence
- The returned total is at most 10 * 1000000 = 10000000
Examples
Input: (1, [7], [0, 0])
Expected Output: 7
Explanation: Minimum valid day: one guest takes the only seat and pays 7 on departure.
Input: (0, [10, 20], [0, 1, 1, 0])
Expected Output: 0
Explanation: With zero seats nobody is ever seated, so both departures are bored departures and nothing is paid.
Hints
- Each occurrence of a guest identifier flips that guest's visit state, so decide what a movement means from that guest's current state rather than from its position in the list.
- A guest's visit state (outside, waiting, seated) is a different thing from whether that guest has already paid today; the payment fact has to survive across later visits.
- A seat that opens up never stays open while someone is still in line - settle that handoff before you read the next movement.