PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Compute peak parking lot occupancy intervals

Last updated: Mar 29, 2026

Quick Overview

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.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Compute peak parking lot occupancy intervals

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

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: ```text [[1, 1, 'entry'], [1, 11, 'entry'], [1, 10, 'exit'], [2, 20, 'exit']] ``` You can assume: - The log list may be unsorted by time. - For questions (1) and (2) below, every `'entry'` has a matching `'exit'` for that `carId`, and exits happen after their corresponding entries. - A car cannot re-enter the lot before it has exited (i.e., intervals for the same `carId` do not overlap). - Multiple events can occur at the same timestamp. For counting occupancy, treat all `'exit'` events at a given timestamp as happening just **before** any `'entry'` events at that same timestamp. Answer the following: 1. **Maximum occupancy count** Compute the **maximum number of cars that are in the parking lot at the same time** over the entire time range covered by the logs. Return this maximum count as an integer. 2. **Intervals with maximum occupancy** Find the **time interval or intervals** during which the number of parked cars is equal to the maximum from (1). Represent each interval as `[startTime, endTime)`, where: - `startTime` and `endTime` are integer timestamps, - the car count is constant and equal to the maximum for all times in `[startTime, endTime)`, - the interval is maximal (you cannot extend it to the left or right without lowering the count). If there are multiple disjoint intervals with the same maximum occupancy, return all of them. 3. **Maximum occupancy when some exits are missing** Now suppose the `'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: - Its true parking interval is `[entryTime, actualExitTime)`, - `entryTime` is the time in its logged `'entry'` record, - if an `'exit'` record exists, then `actualExitTime` is the time in that record, - if an `'exit'` record is missing, then `actualExitTime` is some unknown time satisfying: \[ entryTime < actualExitTime \le entryTime + 2 \] 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.

Quick Answer: 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.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
  • Maximize Value Under a Budget - Amazon (medium)
Amazon logo
Amazon
Dec 2, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

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:

  • The log list may be unsorted by time.
  • For questions (1) and (2) below, every 'entry' has a matching 'exit' for that carId , and exits happen after their corresponding entries.
  • A car cannot re-enter the lot before it has exited (i.e., intervals for the same carId do not overlap).
  • Multiple events can occur at the same timestamp. For counting occupancy, treat all 'exit' events at a given timestamp as happening just before any 'entry' events at that same timestamp.

Answer the following:

  1. Maximum occupancy count
    Compute the maximum number of cars that are in the parking lot at the same time over the entire time range covered by the logs. Return this maximum count as an integer.
  2. Intervals with maximum occupancy
    Find the time interval or intervals during which the number of parked cars is equal to the maximum from (1). Represent each interval as [startTime, endTime) , where:
    • startTime and endTime are integer timestamps,
    • the car count is constant and equal to the maximum for all times in [startTime, endTime) ,
    • the interval is maximal (you cannot extend it to the left or right without lowering the count).
    If there are multiple disjoint intervals with the same maximum occupancy, return all of them.
  3. Maximum occupancy when some exits are missing
    Now suppose the '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:
    • Its true parking interval is [entryTime, actualExitTime) ,
    • entryTime is the time in its logged 'entry' record,
    • if an 'exit' record exists, then actualExitTime is the time in that record,
    • if an 'exit' record is missing, then actualExitTime is some unknown time satisfying:

entryTime<actualExitTime≤entryTime+2entryTime < actualExitTime \le entryTime + 2entryTime<actualExitTime≤entryTime+2

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.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.