← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Got a simulation-style coding problem at Google for a SWE role. The problem looked deceptively manageable at first glance but the priority queue logic and tie-breaking rules made it a lot messier to implement cleanly under pressure.

Questions Asked (1)

Q1

Given a list of people each requesting to pass through a single door (either entering or exiting) at some timestamp, compute the actual time each person uses the door. The door handles one person per time unit, so queues form. Priority rules at ties: the direction used at the previous time step gets priority; if the door was idle, exit wins. Within the same direction, lower index goes first.

Algorithms & Data Structures
Author's notes

The problem statement itself takes a while to parse.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a discrete event simulation where at each time step you determine which person uses the door based on the priority rules. Use two queues (enter and exit) to manage waiting people, and track the door's last direction to apply tie-breaking. Iterate through time, processing arrivals and selecting the next person according to the rules until all are served.

Pro tip: Clarify edge cases upfront, such as simultaneous arrivals and the initial idle state, to ensure your solution handles all scenarios correctly. Also, consider using a priority queue or sorting arrivals by timestamp to efficiently process events in chronological order.

1. Understand the problem and define data structures

Parse the input into a list of events with timestamp, direction, and index. Use two queues (or lists) to represent waiting people for each direction, and maintain variables for current time and last direction.

2. Simulate time step by step

At each time unit, add any new arrivals to the appropriate queue. Then, if the door is free, select the next person based on priority: if both queues non-empty, use last direction (or exit if idle); otherwise pick from the non-empty queue.

3. Apply tie-breaking rules within the same direction

When multiple people are waiting in the same direction, always choose the one with the lowest index (earliest arrival). This ensures fairness as specified.

4. Record usage time and update state

Assign the current time as the usage time for the selected person, remove them from the queue, update last direction, and increment time. Continue until all people have used the door.

5. Return the results

Output the usage times for each person in the original order (by index). Verify with small test cases to ensure correctness.

Key Points to Mention

  • Discrete event simulation approach
  • Two queues for entering and exiting
  • Priority based on last direction, with exit winning if idle
  • Tie-breaking by lower index within same direction
  • Time complexity: O(N log N) if sorting arrivals, or O(N) if already sorted
  • Handling simultaneous arrivals and initial idle state

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.