Skip to content

Tracks · SDE-1, SDE-2

Machine coding and low-level design

In a machine coding round you write real, working classes in about 75 minutes, and then the interviewer adds one new requirement. This track teaches how the round works, how to go from requirements to classes, and the few patterns that matter. It shows three full designs. Then you practise on real problems with an AI interviewer that runs hidden tests and adds the new requirement.

  • 41steps in 5 stages
  • 25 h 35 minin total
  • 7 weeksat 4 hours a week

Start here if you can code well, but your classes get messy when the requirements change.

Skip this track if your round is only about system design for large systems. Use the SDE-2 track.

The track has 22 lessons, 3 trade-offs, 16 practice steps. Steps marked “Free account” are inside the app.

Stage 1 of 5 · 35 min

How the round works

You know how the time is used in the round and what the interviewer checks.

  1. Lesson

    How a machine-coding round works

    What happens in a machine-coding round, how the time is spent, what the interviewer scores, and what to build first.

    12 min
  2. Lesson

    Clarify first: questions, assumptions and the rules list

    How to spend the first minutes of a coding round: ask seven kinds of questions, say your assumptions aloud, and write the answers as a short numbered list of rules.

    23 min

Stage 2 of 5 · 5 h 7 min

The tools of a good design

You can go from requirements to classes, keep classes small, swap behaviour without rewriting, handle bad input, pick the right list, map or heap, and keep shared data safe between threads.

  1. Lesson

    Classes and objects: data and actions in one place

    What a class and an object are, how to read and write a small Python class, and why data and the actions on it belong together.

    21 min
  2. Lesson

    Encapsulation: keep the data safe inside the class

    How to make a class that cannot be put in a wrong state: facts that must always be true, hidden fields, checks in every method, frozen value objects, and enums.

    20 min
  3. Lesson

    Interfaces and polymorphism: one call, many behaviours

    How to replace a chain of if-statements on a kind with an interface, so that a new kind is a new class and the calling code does not change.

    21 min
  4. Lesson

    Composition or inheritance: has-a or is-a

    How to choose between a class that holds another object and a class that is a kind of another class, why inheritance can multiply your classes, and the one place where inheritance is a good fit.

    21 min
  5. Lesson

    SOLID with small examples

    The five SOLID design principles, each shown on a small piece of Python code that you can run: one reason to change, adding without editing, safe substitution, small interfaces, and passing in what a class needs.

    20 min
  6. Lesson

    From requirements to classes, with just enough UML

    How to turn a problem statement into classes: find the nouns and verbs, give each rule an owner, draw a class diagram and a sequence diagram in five minutes, and handle a changed requirement with a small edit.

    23 min
  7. Lesson

    Bad input and errors: check first, change last

    How to make every method do its whole job or change nothing: the kinds of bad input, raising an error or returning a marker value, checking first, all-or-nothing orders, ids that are not used up by a refused call, and cleanup with finally.

    25 min
  8. Lesson

    Testable code: small checks, fakes and a clock you pass in

    How to prove your own code works in five minutes: a tiny check helper, a table of boundary values, a clock and other things you pass in, fakes that stand in for real parts, and how to read a failing check.

    23 min
  9. Lesson

    Lists, maps and sets: pick by the question you ask

    How to pick a list, a dictionary or a set by the question you must answer fast: the cost of each operation in steps, keys that are safe to use, sorting with tie-breaks, text order against number order, and copies.

    26 min
  10. Lesson

    Ordered data: heaps, sorted lists, queues and deques

    How to pick a structure when the question is smallest, oldest, next in line, most recent, or between two values: heap, sorted list with bisect, deque, ordered dictionary, and two queues for delayed work.

    25 min
  11. Lesson

    Strategy, Observer and State

    Three patterns that machine-coding rounds reward, each on small Python code: swap a rule (Strategy), tell everyone who asked (Observer), and change behaviour with the status (State).

    20 min
  12. Lesson

    Factory, Builder and the Singleton trap

    Three creation patterns on small Python code, and the cases where each one is the wrong choice, especially the Singleton, which hides shared state and makes tests fail.

    12 min
  13. Lesson

    Command: undo and redo

    How to turn a request into an object with do and undo: two stacks for undo and redo, a history limit, grouped steps, the cursor, and where else the same idea appears.

    26 min
  14. Lesson

    Thread safety in code

    How to keep shared data correct when many requests run at the same moment: why a counter loses updates, locks, a check followed by a change, atomic steps, deadlock and lock order, a safe cache, and why a lock in code does not protect many servers.

    24 min

Stage 3 of 5 · 1 h 24 min

Three full designs

You have seen how a parking lot, an elevator, a vending machine and shared expenses become clean classes.

  1. Lesson

    Case study: LLD parking lot

    A parking lot from the problem statement to working Python code: find the classes, put the rules that can change in their own small classes, then add monthly passes with a small change.

    28 min
  2. Lesson

    Case study: LLD elevator and vending machine

    Two state machines written as working Python code: a lift (one class for each mode, then a fire alarm as a new class) and a vending machine (a table of legal moves, then a stopped state as three new rows).

    28 min
  3. Lesson

    Case study: LLD Splitwise

    A bill-sharing app from the problem statement to working Python code: debts as a graph, whole-rupee splits with a leftover rule, one place that joins opposite debts, settling up, and fewer payments worked out from each person's total.

    28 min

Stage 4 of 5 · 2 h 12 min

Ideas that many problems use

You know the ideas behind a cache, a rate limiter and a booking, so you do not invent them under pressure.

  1. Lesson

    What to throw out: LRU, LFU and cache size

    What a cache removes when its memory is full, how the main rules (first in first out, random, least recently used, least frequently used) differ, and how to choose the size of a cache.

    23 min
  2. Trade-off

    LRU vs LFU

    Which cache eviction rule to pick, LRU or LFU, with a worked hit-rate example, the cases where each fails, and the size check.

    13 min
  3. DrillFree account

    Product pages slow down after the nightly report

    Practise this decision: LRU or LFU when a big scan runs. Seven minutes.

    7 min
  4. Lesson

    Rate limiting: token bucket, leaky bucket, sliding window

    How to limit the requests one user can send, with five counting methods (fixed window, sliding window log, sliding window counter, token bucket, leaky bucket) and what each one costs.

    24 min
  5. Trade-off

    Token bucket vs sliding window rate limiting

    Which rate limiting method to choose: token bucket or sliding window. The numbers that decide, the bursts each one allows, and what breaks.

    13 min
  6. DrillFree account

    A rate limit must allow the burst of an app screen

    Practise this decision: token bucket or sliding window. Seven minutes.

    7 min
  7. Lesson

    Locking: stop double booking and overselling

    How to make sure two buyers cannot get the same seat or the last item: atomic updates, locks, version checks, unique constraints, and seat holds that expire.

    23 min
  8. Trade-off

    Optimistic vs pessimistic locking

    When to check a version at write time and when to lock a row first, with the clash rates and row limits that decide the choice.

    15 min
  9. DrillFree account

    Two admins edit one menu and one save is lost

    Practise this decision: check at save time or lock first. Seven minutes.

    7 min

Stage 5 of 5 · 16 h 15 min

Practise with an AI interviewer

You have built working code against hidden tests, and handled the new requirement the interviewer adds.

  1. Machine coding mockFree account

    Parking Lot

    Write the class “ParkingLot”. Then the interviewer adds a new requirement: monthly passes and overflow parking.

    1 h 15 min
  2. Machine coding mockFree account

    Tic-Tac-Toe (N x N)

    A small game, but the board must stay fast and a new rule changes how a win is found. Write the class “TicTacToe”. Then the interviewer adds a new requirement: k in a row, and undo.

    1 h 15 min
  3. Machine coding mockFree account

    Vending Machine

    The state idea from the elevator and vending machine lesson, then a new way to pay. Write the class “VendingMachine”. Then the interviewer adds a new requirement: card payments and change in the fewest coins.

    1 h 15 min
  4. Machine coding mockFree account

    ATM

    The state idea once more, now with a PIN, limited notes in the machine, and deposits as the new requirement. Write the class “Atm”. Then the interviewer adds a new requirement: deposits, a daily limit and a mini statement.

    1 h 15 min
  5. Machine coding mockFree account

    LRU Cache with TTL

    Write the class “LruCache”. Then the interviewer adds a new requirement: a second eviction policy: lfu.

    1 h 15 min
  6. Machine coding mockFree account

    Rate Limiter

    Write the class “RateLimiter”. Then the interviewer adds a new requirement: token bucket and retry-after.

    1 h 15 min
  7. Machine coding mockFree account

    Meeting Room Scheduler

    Time ranges that must not overlap, then meetings that repeat. Write the class “MeetingScheduler”. Then the interviewer adds a new requirement: recurring meetings.

    1 h 15 min
  8. Machine coding mockFree account

    Text Editor with Undo and Redo

    Each change is an object that knows how to undo itself, then copy and paste must fit in. Write the class “TextEditor”. Then the interviewer adds a new requirement: copy, cut and paste.

    1 h 15 min
  9. Machine coding mockFree account

    Splitwise (Shared Expenses)

    Write the class “ExpenseManager”. Then the interviewer adds a new requirement: simplify debts.

    1 h 15 min
  10. Machine coding mockFree account

    In-Memory File System

    Folders that hold files and other folders, then copy and move. Write the class “FileSystem”. Then the interviewer adds a new requirement: copy, move and list a whole tree.

    1 h 15 min
  11. Machine coding mockFree account

    Movie Seat Booking

    Write the class “MovieBooking”. Then the interviewer adds a new requirement: coupon codes.

    1 h 15 min
  12. Machine coding mockFree account

    Key-Value Store with Transactions

    Write the class “KeyValueStore”. Then the interviewer adds a new requirement: savepoints inside a transaction.

    1 h 15 min
  13. Machine coding mockCheckpointFree account

    Elevator

    Your checkpoint: the interviewer adds a requirement late, as in a real round. Write the class “Elevator”. Then the interviewer adds a new requirement: fire alarm: emergency recall to the ground floor.

    1 h 15 min

Estimates

How the time is counted

These times are planning estimates, not deadlines. Yours will vary.

  • Lessons and trade-off pages: the number of words divided by 130, rounded, plus 4 minutes to think.
  • A Drill: about 7 minutes. A system design mock: allow about 45 minutes. A machine coding mock: allow about 75 minutes.
  • Other mocks: a SQL mock with one problem, about 29 minutes. A behavioural mock, about 36 minutes. A resume mock, about 35 minutes. A coding mock, about 45 minutes.
  • A simulator level or a Cost Lab workload: allow about 15 minutes. This is our own estimate for a first try. It can take you less or more.
  • Incident investigation: time varies. The room has a simulated clock; your real time depends on how you investigate. It has no fixed time, so it is not counted in any total.
  • The total is the sum of all steps that have a time. The weeks are the hours divided by 4, rounded up. We assume 4 hours a week, like a person with a job. Doing a step again is not counted.

Ready for the checkpoint?

The last step is a mock interview with an AI interviewer. It gives you a report that shows what you did well and what was missing.