Skip to main content
LLD Interview Cheatsheet
πŸ–¨οΈ Print this page! This cheat sheet contains everything you need to review before an LLD interview.

⏱️ The 45-Minute Framework

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PHASE 1: REQUIREMENTS (5 min)                                   β”‚
β”‚  βœ“ What are the core features? (ask for top 3-4)                β”‚
β”‚  βœ“ Who are the users/actors?                                    β”‚
β”‚  βœ“ Any scale/performance constraints?                           β”‚
β”‚  βœ“ What's explicitly OUT of scope?                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  PHASE 2: CORE DESIGN (20 min)                                   β”‚
β”‚  βœ“ Identify nouns β†’ Classes                                     β”‚
β”‚  βœ“ Identify verbs β†’ Methods                                     β”‚
β”‚  βœ“ Define relationships (is-a, has-a, uses)                     β”‚
β”‚  βœ“ Draw class diagram with key attributes/methods               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  PHASE 3: IMPLEMENTATION (15 min)                                β”‚
β”‚  βœ“ Code the core happy path                                     β”‚
β”‚  βœ“ Apply relevant design patterns                               β”‚
β”‚  βœ“ Handle important edge cases                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  PHASE 4: DISCUSSION (5 min)                                     β”‚
β”‚  βœ“ Explain your trade-offs                                      β”‚
β”‚  βœ“ Discuss how to extend for new requirements                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Pro Move: If running low on time, skip some implementation and explain what you would do. Interviewers value thought process over perfect code.

πŸ“‹ Requirements Gathering Questions

Always ask before designing:
CategoryQuestions to AskWhy It Matters
ScopeWhat are the must-have features? What can we skip?Prevents over-engineering
UsersWho interacts with the system? (Customer, Admin, System)Defines access control needs
ScaleSingle machine or distributed? How many concurrent users?Threading/locking decisions
DataWhat needs to be persisted? Any real-time requirements?Database design
Edge CasesWhat happens on failure? Concurrent access handling?Shows senior thinking

πŸ—οΈ OOP Quick Reference

The Four Pillars - One-Liner Each

PillarWhat It MeansCode Signal
EncapsulationHide internals, expose interfaceprivate fields + public methods
AbstractionDefine WHAT, hide HOWabstract classes, interfaces
InheritanceShare behavior from parentextends / : Base
PolymorphismSame interface, different behaviorOverride methods, common interface
# 1. ENCAPSULATION - Bundle data + methods, hide internals
class Account:
    def __init__(self):
        self.__balance = 0  # Private (use __ prefix)
    
    def deposit(self, amount):  # Public interface
        if amount > 0:
            self.__balance += amount
    
    @property
    def balance(self):  # Read-only access
        return self.__balance

# 2. ABSTRACTION - Define what, not how
from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self) -> float:
        pass  # Subclasses MUST implement

# 3. INHERITANCE - Reuse and extend
class Dog(Animal):  # Dog IS-A Animal
    def __init__(self, name):
        super().__init__(name)
        self.breed = None
    
    def speak(self):  # Override parent
        return "Woof!"

# 4. POLYMORPHISM - Same interface, different behavior
def make_sound(animal: Animal):
    print(animal.speak())  # Works for Dog, Cat, Bird...

make_sound(Dog("Rex"))   # "Woof!"
make_sound(Cat("Luna"))  # "Meow!"

⚑ SOLID Principles

PrincipleOne-LinerCode Smell
S - Single ResponsibilityOne class = one reason to changeClass has 10+ methods doing different things
O - Open/ClosedOpen for extension, closed for modificationAdding feature requires editing existing classes
L - Liskov SubstitutionSubtypes must be substitutableSubclass throws β€œnot implemented” exceptions
I - Interface SegregationMany specific interfaces > one generalClass implements interface methods it doesn’t need
D - Dependency InversionDepend on abstractions, not concretionsClass instantiates dependencies with new

Quick Examples

# ❌ SRP Violation
class User:
    def save_to_db(self): pass      # Persistence
    def send_email(self): pass       # Notification
    def generate_report(self): pass  # Reporting

# βœ… SRP Applied
class User: pass
class UserRepository:
    def save(self, user): pass
class EmailService:
    def send(self, user, msg): pass

# ❌ DIP Violation
class OrderService:
    def __init__(self):
        self.db = MySQLDatabase()  # Concrete dependency

# βœ… DIP Applied
class OrderService:
    def __init__(self, db: Database):  # Abstract dependency
        self.db = db

🧩 Design Patterns Cheat Sheet

When to Use What?

SituationPatternExample
Need only ONE instanceSingletonDatabase, Logger, Config
Create objects without specifying classFactoryVehicles, Notifications, Payments
Complex object with many optional partsBuilderPizza, HTTP Request, Query
Make incompatible interfaces workAdapterLegacy system integration
Add features dynamicallyDecoratorCoffee toppings, Middleware
Simplify complex subsystemFacadeVideo converter, Payment gateway
Swap algorithms at runtimeStrategySorting, Payment, Shipping
Notify many objects of changesObserverStock price, Notifications
Object behavior changes with stateStateOrder status, Elevator, ATM
Undo/redo operationsCommandText editor, Transactions

Pattern Code Templates

import threading

class Database:
    _instance = None
    _lock = threading.Lock()
    
    def __new__(cls):
        if cls._instance is None:
            with cls._lock:  # Thread-safe
                if cls._instance is None:
                    cls._instance = super().__new__(cls)
        return cls._instance
    
    def query(self, sql):
        pass

# Usage
db1 = Database()
db2 = Database()
assert db1 is db2  # Same instance

πŸ“Š UML Class Diagram Notation

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              ClassName                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ + publicAttr: Type                           β”‚  + = Public
β”‚ - privateAttr: Type                          β”‚  - = Private
β”‚ # protectedAttr: Type                        β”‚  # = Protected
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ + publicMethod(): ReturnType                 β”‚
β”‚ - privateMethod(): void                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

RELATIONSHIPS:
═══════════════════════════════════════════════
A ────────▷ B     INHERITANCE: A extends B
A - - - - β–· B     IMPLEMENTATION: A implements B
A ◆───────── B     COMPOSITION: A contains B (B dies with A)
A ◇───────── B     AGGREGATION: A has B (B can exist alone)
A - - - - -> B     DEPENDENCY: A uses B
A ──────────> B     ASSOCIATION: A knows B
═══════════════════════════════════════════════
MULTIPLICITY: 1, 0..1, *, 1..*, n..m

🚨 Common Interview Problems

Parking Lot System

Classes: ParkingLot, Floor, ParkingSpot, Vehicle, Ticket, Payment
Patterns: Strategy (payment), Singleton (parking lot)
Key: Different spot sizes for different vehicles

Elevator System

Classes: Elevator, ElevatorController, Floor, Button, Request
Patterns: State (elevator states), Strategy (scheduling)
Key: Multiple elevators, efficient scheduling algorithms

Library Management

Classes: Library, Book, BookCopy, Member, Lending, Reservation
Patterns: Strategy (search), Observer (notifications)
Key: Book vs BookCopy distinction, reservation queue

Chess Game

Classes: Game, Board, Piece (King, Queen, etc.), Move, Player
Patterns: Factory (piece creation), Command (moves for undo)
Key: Each piece type has unique move validation

❓ Interview Discussion Points

Be ready to answer:
  • β€œWhy did you use inheritance here instead of composition?”
  • β€œHow would you add a new payment method?”
  • β€œWhat happens if two users try to book the same spot?”
  • β€œHow would you handle this at 10x scale?”
  • β€œWhere would you add logging/monitoring?”
  • β€œHow would you test this design?”
Power phrases:
  • β€œI chose X over Y because…”
  • β€œThe trade-off here is…”
  • β€œThis follows the Open/Closed principle because…”
  • β€œAdding new feature Z would just require…”
  • β€œFor concurrency, we could use…”

βœ… Pre-Interview Checklist

  • Review the 4 pillars of OOP
  • Memorize SOLID principles
  • Know 5-6 key design patterns cold
  • Practice 2-3 problems end-to-end
  • Have your IDE or whiteboard ready
  • Review this cheat sheet!
  • Clarify requirements FIRST (spend 5 min)
  • Think out loud - explain your reasoning
  • Start simple, then add complexity
  • Draw class diagram before coding
  • Apply patterns where appropriate
  • Mention edge cases even if you don’t code them
  • Don’t jump into coding immediately
  • Don’t over-engineer with unnecessary patterns
  • Don’t forget about thread safety for shared resources
  • Don’t ignore error handling completely
  • Don’t make assumptions - ask questions
  • Don’t try to implement everything perfectly

Remember: LLD interviews test your thought process as much as your design. A simple, well-reasoned design beats a complex, unexplained one every time.