PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

From entry/exit logs, return the maximum occupancy and maximal intervals at that occupancy. Missing exits may use max_stay when provided.

Constraints

  • Logs may be unsorted
  • Intervals are half-open [entry, exit)

Examples

Input: ([[1, 1, 'entry'], [1, 10, 'exit'], [2, 5, 'entry'], [2, 8, 'exit']], None)

Expected Output: {'max': 2, 'intervals': [[5, 8]]}

Explanation: Peak overlap between two parked cars.

Input: ([[1, 1, 'entry'], [1, 3, 'exit'], [2, 3, 'entry'], [2, 5, 'exit']], None)

Expected Output: {'max': 1, 'intervals': [[1, 3], [3, 5]]}

Explanation: Exits at a timestamp happen before entries.

Input: ([[1, 1, 'entry'], [2, 2, 'entry'], [2, 4, 'exit']], 2)

Expected Output: {'max': 2, 'intervals': [[2, 3]]}

Explanation: Missing exit uses latest allowed exit to maximize occupancy.

Input: ([], None)

Expected Output: {'max': 0, 'intervals': []}

Explanation: No logs.

Hints

  1. Convert car logs to intervals, then sweep timestamp deltas with exits before entries.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)