Low-level design interview questions
12 object-oriented design questions with an answer key each: what to confirm, which classes exist, how they connect, which pattern fits and where answers usually go wrong. Write your own class list first, then open the key.
The five steps every answer follows
- 1. Clarify. Ask what is in scope and write down four or five requirements before you name a class.
- 2. Name the entities. List the nouns in the requirements, then give each class exactly one job.
- 3. Connect them. Say who owns whom and who only refers to whom, and put whatever varies behind an interface.
- 4. Code the core. Write the main interfaces and one real method. Leave getters and setters out.
- 5. Stress it. Walk through the edge cases and one new requirement, and show that the change is a new class and not an edit.
Pick a question
- Design a parking lotDesign the classes for a multi-floor parking lot that issues a ticket on entry and charges on exit.Fresher
- Design tic-tac-toeDesign a two-player tic-tac-toe game that can be extended to an N by N board.Fresher
- Design snake and ladderDesign a snake and ladder game for several players on a 100-cell board.Fresher
- Design a library management systemDesign a library system where members search for books, borrow copies and return them.Fresher
- Design a vending machineDesign a vending machine that takes coins or notes, lets the user pick a product and returns change.SDE-1
- Design an LRU cacheDesign an in-memory cache with a fixed capacity that evicts the least recently used entry, with get and put in constant time.SDE-1
- Design an elevator systemDesign the control software for a building with several elevators.SDE-1
- Design an expense-sharing appDesign the classes for an app where friends record shared expenses and see who owes whom.SDE-1
- Design a movie ticket booking systemDesign the classes for booking seats for a movie show, where two people must never get the same seat.SDE-1
- Design a logging frameworkDesign a logging library that an application uses to write messages at different levels to different destinations.SDE-1
- Design an in-memory file systemDesign an in-memory file system with directories and files that supports create, read, write, list and delete by path.Senior
- Design a chess gameDesign a two-player chess game that validates moves and detects check, checkmate and stalemate.Senior
Looking for servers and scale instead? System design practice
Questions
- What is a low-level design (LLD) interview?
- A low-level design round, also called an object-oriented design or machine coding round, asks you to turn a small product such as a parking lot or a cache into classes: which objects exist, what each one owns, how they talk to each other and where the design can change. It sits between a DSA round (one function) and a system design round (servers and databases). The answer is judged on clear responsibilities, sensible relationships and whether a new requirement becomes a new class or a rewrite.
- How is low-level design different from system design?
- System design, also called high-level design, is about machines: services, databases, caches, queues and how they scale. Low-level design is about the code inside one of those services: classes, interfaces, relationships and design patterns. A parking lot question has no load balancer in it, and a URL shortener question has no class diagram. Many interview loops ask one round of each, so practise both.
- Which design patterns should I know for LLD interviews?
- A small set covers most questions: Strategy (a rule that varies, such as pricing), State (behaviour that depends on a mode, such as a vending machine), Observer (tell others without knowing them), Factory (creation with real branching), Composite (trees such as a file system), Decorator (behaviour added around an object) and Command (actions you can undo). Name a pattern only when you can say what breaks without it. The 12 questions here show where each one fits and where it would only be decoration.
- Do I have to write full code in an LLD round?
- Usually not all of it. A discussion round wants the class list, the key interfaces and one or two core methods written properly, in the language you know best. A machine coding round gives more time and expects a program that runs. Either way, start with the requirements and the entities: code written before the model is agreed is the most common way to run out of time.