This question evaluates a candidate's competency in temporal interval reasoning, event-stream processing, and handling incomplete or unsorted logs to determine peak concurrent occupancy.
You are given logs from a parking lot system. Each log entry has the form:
[carId, time, eventType]
carId
is an integer identifying a car.
time
is an integer timestamp (e.g., minutes or hours).
eventType
is a string, either
'entry'
or
'exit'
.
Example log list:
[[1, 1, 'entry'], [1, 11, 'entry'], [1, 10, 'exit'], [2, 20, 'exit']]
You can assume:
'entry'
has a matching
'exit'
for that
carId
, and exits happen after their corresponding entries.
carId
do not overlap).
'exit'
events at a given timestamp as happening just
before
any
'entry'
events at that same timestamp.
Answer the following:
[startTime, endTime)
, where:
startTime
and
endTime
are integer timestamps,
[startTime, endTime)
,
'exit'
scanner is faulty: some
'exit'
events are missing from the logs, but
all 'entry' events are still recorded correctly
.
The parking lot has a policy that
no car may stay longer than 2 hours
. Formally, for each car:
[entryTime, actualExitTime)
,
entryTime
is the time in its logged
'entry'
record,
'exit'
record exists, then
actualExitTime
is the time in that record,
'exit'
record is missing, then
actualExitTime
is some unknown time satisfying:
Under these conditions, you do not know the exact exit times for cars with missing exit logs, only that each such car must leave within 2 hours of its entry.
Design an algorithm that, given this incomplete log data and the 2‑hour constraint, computes the time interval or intervals during which the parking lot could have the largest possible number of cars parked simultaneously, assuming the (unknown) exit times are chosen adversarially (or optimally) to maximize the peak occupancy, but must still satisfy the constraints above.
As in (2), return the interval(s) as [startTime, endTime) with maximum possible occupancy.
Describe your algorithm(s), including time and space complexity, for all three subproblems.