Preparing for an interview? Check out Cracking the Coding Interview
Published on

Google | L4 | Screening Round

Author
  • Shared Anonymously

There is a door and people can go in or out. Passing the door takes 1 second. There can be a queue waiting to pass on both sides if many people arrive at the door in a short time.

When there are people waiting on both sides:

If there is a person going in in the last second, then the person waiting to go in should go first.
If there is a person going out in the last second, then the person waiting to go out should go first.
If two people arrive at the door at the same time, and there was no one passing the door in the last second, then the person going out should go first.
Given a list of arriving people, each with a positive integer indicating the arrival timestamp (second) and their direction (in or out), return the actual passing timestamp of each person.

Example:

Input: [(1, in), (1, out), (1, in), (2, out), (9, out)]

Output: [3, 1, 4, 2, 9]

ReportMark as Helpful