End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
enterQueue and exitQueue.result to store the time each person crosses the door.currentTime to 0 and lastAction to -1 (indicating the door was not used in the previous second).arrival and state arrays:
a. For each person, if their state is 0 (enter), enqueue their index to enterQueue.
b. If their state is 1 (exit), enqueue their index to exitQueue.enterQueue or exitQueue is not empty:
a. If currentTime is less than the arrival time of the person at the front of both queues, increment currentTime and set lastAction to -1.
b. Otherwise, determine which queue has priority based on lastAction and the rules.
c. Dequeue the person from the queue with priority and set their crossing time in result.
d. Update lastAction based on the action taken and increment currentTime.result array.