← 返回 instacart 的题目列表Bus Boarding Simulation (Priority + Wheelchair Capacity)
类型:online_judge
Implement a bus boarding simulator with regular riders, priority boarding, and wheelchair constraints.
Design and implement functions/classes to support the following (progressive) requirements:
Base model
Person has a unique id and a boolean priority flag.
Bus has total capacity measured in seat-units.
People wait in a queue at a stop.
Task 1: Priority boarding
When a bus arrives, board people until the bus is full or the queue is empty.
Priority riders board before regular riders.
Within the same priority level, maintain FIFO.
Return the boarded id list in boarding order.
Task 2: Explain design and trade-offs (verbal)
Explain your approach (two queues vs stable partition vs priority queue, etc.) and discuss time/space, testability, and how you’d do it in production (concurrency, consistency, auditing, observability).
Task 3: Unit tests for Task 1
Write unit tests covering: only-regular/only-priority, mixed FIFO, insufficient capacity, and edge cases.
Task 4: Add wheelchair rules
Some people may have wheelchair=True.
Each bus allows at most 2 wheelchair riders.
Each wheelchair rider consumes wheelchair_cost seat-units; non-wheelchair consumes 1.
Still enforce: priority before regular; FIFO within same priority.
Return boarded id list, ensuring capacity and wheelchair-slot constraints.
Constraints (typical)
Queue length n up to 1e5
capacity up to 1e9
Test cases
Example
Input
capacity=3
queue=[(A,p=1,w=0),(B,p=0,w=0),(C,p=1,w=0),(D,p=0,w=0)]
Output
A C B