Amazon·Software Engineer·Technical Phone Screen
- Given an unsorted list of parking lot log entries in the form [carId, time, eventType], where eventType is either 'entry' or 'exit', compute the maximum number of cars simultaneously in the lot. Treat all exits at a given timestamp as happening just before any entries at that same timestamp.
- Using the same parking lot logs, find all maximal time intervals during which the number of parked cars equals the maximum occupancy from the previous part. Return each interval as [startTime, endTime).
- Now suppose some exit events are missing from the logs but all entry events are present. The lot has a policy that no car stays longer than 2 hours. For cars with missing exit records, the actual exit time is unknown but must satisfy entryTime < actualExitTime <= entryTime + 2. Design an algorithm to find the time interval(s) during which the parking lot could have the largest possible simultaneous occupancy, assuming exit times for cars with missing logs are chosen to maximize the peak. Return the interval(s) as [startTime, endTime).
“Classic sweep line problem once you see it that way.”