Skip to main content

How to approach machine coding interviews

A machine coding round asks for the same thing an OOD interview asks for - clarify scope, find entities, find relationships, find methods - and then adds one unforgiving constraint that changes almost everything about how you should spend your time: in 60-90 minutes, it has to actually run. A beautiful diagram that never became working code is a failed attempt here, in a way it never was in a pure design conversation. See how to approach OOD interviews for the design flow itself - this page is about budgeting that flow against a clock and a compiler.

Time-box the design before you touch the keyboard

The instinct under time pressure is to start typing immediately. Resist it for the first 10-15 minutes. A design worked out on paper (or out loud) takes minutes to fix; a design discovered to be wrong after 40 minutes of code takes the rest of the round to fix, if there's any round left. Spend that window doing exactly what an OOD interview asks for - scope, entities, relationships, methods - but compressed and written down as a rough skeleton (class names and method signatures, no bodies) rather than a polished diagram. Nobody is grading the diagram's aesthetics here; they're grading whether the skeleton compiles into something later.

Build incrementally, not top-down

The other common failure mode is designing the entire system - every class, every edge case, every future extension - before writing a single working line. That front-loads all the risk into the coding phase and leaves you with a half-finished pile at time's up. Instead:

  1. Get the smallest useful path running first. For a parking lot: one lot, one level, park a car, look up its spot. No pricing, no reservations, no levels yet. This gets you a green checkmark and a program you can actually demo in minute 15, not minute 80.
  2. Layer in complexity one piece at a time. Add levels. Add a pricing strategy. Add validation for a full lot. Each layer is a small, testable addition to something that already works, rather than a new front you're opening on an unfinished war.
  3. Keep classes small enough to finish. A ParkingLot god-class that owns levels, pricing, payment and notifications is a class you will not finish implementing in the time given. Split responsibilities early enough that each piece is small enough to actually type out.

Try it yourself: for "design a vending machine", write down what the smallest useful path would be (one product slot, insert exact change, dispense) and what you'd layer on next, in order - before you'd let yourself start typing the full thing.

Don't design for requirements nobody gave you

This is YAGNI (see the design principles page) under a much sharper deadline. Building an AbstractPricingStrategyFactory for a system that currently has one pricing rule doesn't demonstrate design maturity in a machine coding round - it demonstrates that you spent code-writing time on a class with no caller. Add the interface and the factory the moment a second concrete pricing rule shows up, not before. If the prompt tells you up front that multiple rules are coming, that's different - now you have a real second requirement to design against, today.

The same restraint applies to defensive code. Validating inputs that the interviewer told you are always well-formed, or handling concurrent access nobody asked about, spends your scarce minutes defending against a scenario that isn't in scope. Ask if you're unsure whether it's in scope; don't assume the hardest possible version of the problem by default.

What a strong finish looks like

With minutes left, the version of "done" that reads well is a small main (or a handful of unit tests) that exercises the design end to end: park a few cars, hit capacity, remove one, park another, maybe trigger the pricing calculation. It doesn't need to cover every branch - it needs to prove the pieces you built actually talk to each other.

The version that reads poorly is the opposite of that: five classes that each compile in isolation but were never wired together, because all the remaining time went into typing rather than integrating. If you have to choose between finishing one path fully and starting three paths partially, finish the one path. A working subset beats an ambitious mess, and an interviewer can always ask "what would you add next" to find out you know exactly what's missing.