Skip to content

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.

  • Lesson 105 of 125
  • 12 min read
  • Core
  • Free to read, no account
On this page
  1. Why interviewers ask this
  2. The idea in plain words
  3. Pause and predict
  4. Worked example
  5. Trade-offs
  6. Common misconceptions
  7. How to say it in the interview
  8. Check your understanding
  9. Answers
  10. Sources

01Why interviewers ask this

Some product companies run a round where you write working code for a small problem, such as a parking lot. They run your code and then change a rule. Time and scoring differ by company, so ask at the start.

A weak candidate designs for too long, or codes without a plan. A strong one asks questions, runs a simple version early, and keeps the code ready for a new rule.

02The idea in plain words

Think about a one-day market. You must build a small stall and sell something before the market closes. A pretty stall that sells nothing fails. A stall that breaks when the owner asks for one change also fails.

A machine-coding round gives you one small problem, a fixed time and an editor. You write code that runs, with no database and no web server. Everything stays in memory. A requirement is a rule the code must follow. The core is the main rules from the problem statement. After the core, the interviewer adds one new requirement, and you change your code to match it.

The Tradeoff practice round is the example here. It plans 75 minutes and stops at 90. It has five steps. The times are upper limits:

StepWhat you doLimit
ClarifyAsk what is unclear, say your assumptions10 minutes
Class designName the classes and what each one does15 minutes
Code the coreWrite code that runs, test it often35 minutes
New requirementAdd the new rule without breaking the old ones15 minutes
Wrap-upSay what you would test and improve5 minutes

The Tradeoff scoring has six parts. These are the weights out of 100:

  • Clarifying requirements: 10
  • Object design (each class has one clear job): 25
  • Working code (hidden tests on your code): 25
  • Extensibility (the new requirement fits in a small change): 20
  • Code quality (clear names, short methods): 10
  • Communication (short, clear steps): 10

What to build first: the thinnest path that runs from start to end. For a parking lot, that is "park a car" and "leave and pay". Run it. Then add edge cases, such as a full lot or an unknown ticket. Do not build what nobody asked for, such as a database or a screen.

Stuck on something? The AI tutor has read this lesson. Ask it with a free account

03Pause and predict

Pause. Guess first.

A round has 75 minutes. Clarifying takes 10 minutes, and you spend 40 minutes on a perfect class design. How many minutes are left for the code, the new requirement and the wrap-up together?

Write your guess before you read on. The answer is in the worked example.

04Worked example

A parking lot. Assumption: the round is 75 minutes.

A good plan.

MinutesWork
0 to 10Ask: which vehicle sizes? How is the fee worked out? What if the lot is full? Write the answers down.
10 to 25Classes: ParkingLot (the class the tests call), Slot, Ticket, FeeRule. One line for each.
25 to 40Code park and leave with a fixed fee. Run it.
40 to 55Add "lot full" and "unknown ticket", then the real fee rule.
55 to 70New requirement, for example monthly passes. Add a new fee rule. Do not change park.
70 to 75Wrap-up: what to test and improve.

The steps add up: 10 + 15 + 15 + 15 + 15 + 5 = 75.

The predict box. 75 - 10 - 40 = 25 minutes remain. The good plan gives code, new requirement and wrap-up 30 + 15 + 5 = 50 minutes. With only 25, you may never reach the new requirement. It is worth 20 of the 100 points.

A score. Assumption: a candidate passes 9 of 11 core tests, which gives 9 / 11 x 100 = 82 (rounded). The other scores are made up: clarifying 60, design 70, extensibility 80, code quality 70, communication 60. Each score is multiplied by its weight: 600 + 1,750 + 2,050 + 1,600 + 700 + 600 = 7,300. Divide by 100: 73.

05Trade-offs

A thin version first solves the risk of having nothing to show. It costs some tidiness, which you fix as you go. I would change the order if the interviewer asks for a design talk before any code.

06Common misconceptions

"Design everything first, then code." The round gives 15 minutes to class design. After 40 minutes of design, only 25 minutes remained.

"More features give more points." The tests check what the statement asks. An unasked database takes minutes and earns nothing.

"My examples work, so I am done." The tests also try a full lot and an unknown ticket.

07How to say it in the interview

Say it like this

I first ask what is in scope and say my assumptions aloud, then sketch the classes in a few minutes. I get the simplest version running early, add edge cases, and keep the code ready for one new rule.

08Check your understanding

  1. Name the five steps of the round in order.
  2. A round is 80 minutes. You plan clarify 8, design 12, code 35 and wrap-up 5. How many minutes are left for the new requirement? If you skip it and earn 0 points for that part, what is the best total score, with the weights above?
  3. At minute 30 of 75 your class drawing is perfect, but nothing runs. What do you do?

09Answers

Show the answers
  1. Clarify, class design, code the core, new requirement, wrap-up.
  2. 80 - (8 + 12 + 35 + 5) = 20 minutes. The new requirement is worth 20 of 100 points, so with 0 for that part the best total is 100 - 20 = 80.
  3. Stop drawing. Write the thinnest path that runs, such as park and leave. Run it, then add the edge cases, and keep 15 minutes for the new requirement.

10Sources

  • The steps, the times, the 75 and 90 minute limits and the six weights are from the Tradeoff machine-coding practice round (docs/specs/machine-coding-round.md). Other companies use other rules.
  • The plan, the test counts and the scores are assumptions made for teaching.

Try it now, no sign-up

More practice, in the app (free account)

Ask the AI tutor about this lesson

The tutor has read this lesson. Ask in your own words, any time. Free account, 20 questions a day.

Reading never needs an account. The account is for the tutor, the quiz, your notes and your progress.

All lessons in Module 17: Low-level design and machine coding