Skip to content

Day 7: Parking lot System :

This day is designed to feel exactly like an SDE-1 machine coding round.
⏱ Time-bound
📄 Clear problem statement
🧱 Given structure & signatures
🧪 Deterministic tests
❌ No hints during coding
✅ Focus only on correct implementation

🟢 Day 7 — Full Machine Coding Simulation (SDE-1 Level)

🎯 Day 7 Objective

By the end of Day 7, the candidate should be able to:
Read a large problem statement
Identify required classes and responsibilities
Implement logic inside given method signatures
Handle multiple interacting objects
Respect constraints & state transitions
Pass all tests within 60–90 minutes
This day answers one question: ​“Can you clear a real machine coding round?”

⏱️ Interview Simulation Rules (IMPORTANT)

Give these rules to the candidate before starting:
⏰ Time limit: 90 minutes
❌ Do NOT change class names or method signatures
❌ Do NOT add new public methods
❌ Do NOT modify test file
✅ You may add private helpers if needed
✅ Return values exactly as specified
❌ No print statements in solution

🧩 The Problem — Parking Lot System (Simplified)

Problem Statement

You are implementing a Parking Lot system.
The system supports:
Multiple parking spots
Parking and un-parking vehicles
Tracking availability
This is a state-heavy, rule-heavy machine coding problem.

🚗 System Rules

Parking Spot States

Each parking spot can be:
FREE
OCCUPIED

Vehicle Rules

Each vehicle has a unique vehicle_id
One vehicle occupies one spot
Same vehicle cannot be parked twice

🧱 Class Definitions (DO NOT MODIFY)

class Vehicle:
def __init__(self, vehicle_id: str):
pass


class ParkingSpot:
def __init__(self, spot_id: int):
pass

def park(self, vehicle: Vehicle) -> bool:
pass

def unpark(self) -> bool:
pass

def is_free(self) -> bool:
pass

def get_vehicle(self):
pass


class ParkingLot:
def __init__(self, total_spots: int):
pass

def park_vehicle(self, vehicle: Vehicle) -> bool:
pass

def unpark_vehicle(self, vehicle_id: str) -> bool:
pass

def get_available_spots(self) -> int:
pass

📋 Detailed Requirements (READ CAREFULLY)

Vehicle

Store vehicle_id

ParkingSpot

Initial State
Spot is FREE
No vehicle assigned
park(vehicle)
If spot is already OCCUPIED → return False
Else:
Assign vehicle
Mark as OCCUPIED
Return True
unpark()
If spot is FREE → return False
Else:
Remove vehicle
Mark as FREE
Return True
is_free()
Return True if FREE, else False
get_vehicle()
Return vehicle object if OCCUPIED
Else return None

ParkingLot

__init__(total_spots)
Create total_spots ParkingSpot objects
Spot IDs should start from 1
park_vehicle(vehicle)
If vehicle already parked → return False
Find the first FREE spot
Park the vehicle
Return True if parked
If no free spot → return False
unpark_vehicle(vehicle_id)
Find spot containing this vehicle
If found:
Unpark it
Return True
If not found → return False
get_available_spots()
Return number of FREE spots

🧠 Expected Thinking Process (Not Code)

Candidate should think:
ParkingLot manages many ParkingSpots
ParkingSpot manages one Vehicle
Vehicle is a simple data object
State lives inside ParkingSpot
ParkingLot coordinates operations
Must prevent duplicate vehicle parking

🧪 (Given to Candidate)

class Vehicle:
def __init__(self, vehicle_id: str):
pass


class ParkingSpot:
def __init__(self, spot_id: int):
pass

def park(self, vehicle: Vehicle) -> bool:
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.