00:00

Problem Statement

Input/Output Examples

Visual Explanation

The fee rule is max(1, ceil(minutes / 60)) × 40, written with integers as (minutes + 59) / 60.

Approaches

Both approaches allocate the same spots and charge the same fees on 5,000 random test runs. They differ in how a free spot is found.

Java Solutions

Each tab is a complete program that runs on Java 17 or later. Both programs print the same output for the same inputs.

Complexity Analysis

With one sorted set per size, parking and leaving cost O(log s). The scan costs O(s) in the worst case, when most spots are taken.

Interview Tips and Recommended Approach

  • Start with the entities: lot, spot, vehicle size, ticket and a fee policy.
  • Make the fee a separate strategy so weekend or per-vehicle rates do not change the lot.
  • Store money as integers, never as double.
  • Discuss concurrency: two gates parking at once must not get the same spot, so allocation must be atomic.

Recommended Approach: Free-Spot Sets per Size

Why: finding a spot stays fast however full the lot is, and the free sets make the allocation rule easy to see.