How ML coding interviews work
An ML coding round asks you to write machine learning code without the high-level library: a model such as logistic regression or k-means, a component such as attention or an optimizer, a metric such as ROC-AUC, or the data code that turns raw tables into features. It usually runs 50 to 60 minutes in a shared editor, most often in NumPy. The guides we read agree that the signal is not a recalled solution but code that is right for real data: shapes stated, stable math, no leakage, and tests beyond the sample output.
Key points
- Ask what is allowed before you code: NumPy only or a library, gradient descent or a closed form.
- Say the shape of every array as you go. Indexing and broadcasting are where much of the difficulty hides.
- Make the math stable: subtract the maximum before a softmax, clip before a log.
- Fit scaling and imputation on the training split only. Leakage in data code is a reported failure.
- Test more than the sample: an edge case, a shape check, and a loss that goes down.
The usual shape of the round
Formats vary more than in general coding rounds. One prep guide lays out a 50-minute plan like the one below, and calls it a practice framework rather than a fixed schedule; when the task is a single function, the saved time goes to examples, edge cases and complexity.
| Step | Typical time | What happens |
|---|---|---|
| Clarify | About 5 min | The target, the data shape, which libraries are allowed, the split and the metric. |
| Inspect the data | About 5 min | Keys, types, missing values, class balance and dimensions. |
| Data path | About 15 min | The simplest correct, vectorized path from raw data to training and validation arrays. |
| Model and metric | About 13 min | Training, prediction and a baseline metric, end to end. |
| Test | About 8 min | Edge cases, shape checks and whether training converges. |
| Explain | About 4 min | Complexity, limitations and the next improvement. |
What you may be asked to write
- Classical models from scratch: linear and logistic regression with gradient descent, k-means, k-nearest neighbors, naive Bayes.
- Model components: attention, a dense layer with its gradient, normalization, an optimizer such as Adam.
- Metrics: ROC-AUC, precision and recall, a confusion matrix, ranking metrics such as nDCG.
- Array utilities: a stable softmax, pairwise distances or top-k similarity without a huge intermediate array.
- Data code: joins, rolling features and time-aware splits in pandas, with nothing from the future in the features.
- Pieces of language-model inference: sampling, beam search, a cache for keys and values.
What interviewers look for
No company publishes its ML coding rubric. The guides describe the same signals:
- Correctness: shapes, invariants and the expected output stated before coding, not inferred from the sample.
- Understanding: why the update rule learns, and how the objective, the gradient and the metric connect.
- Numerical stability: large logits, zero variance and empty clusters handled instead of returning NaN.
- Data hygiene: keys checked before joins, preprocessing fitted on training data only, splits that respect time.
- Efficiency: vectorized code that does not build an enormous intermediate array.
- Communication and testing: assumptions said out loud, and checks that show the code works.
The mistakes guides report most
- Fitting scaling or imputation on all rows, which leaks validation data into training.
- Ignoring duplicate join keys, so rows multiply silently.
- Unstable math that returns infinity or NaN on valid inputs.
- Row-by-row Python loops where a vectorized operation would do.
- Optimizing before one correct end-to-end path works.
- Reporting accuracy alone on imbalanced data.
- Looking up the framework for every line, so the time runs out.
How the interviewer behaves
Follow-ups test whether the code would survive real data: what if the join key is duplicated, was the imputer fitted before or after the split, what happens when a logit is very large. Expect to explain every line, including the gradient’s shape, the learning rate and why the features are scaled.
Not every interviewer values this format. One essay written from the interviewer’s side calls from-scratch ML coding low in signal, because much of its difficulty sits in array indexing that the interviewer cannot see, and prefers a live modeling exercise instead. Loops differ in how much weight they give it, and some ML loops keep a general algorithms round as well.
Other formats: debugging and live modeling
Some loops replace from-scratch coding with debugging: you get model code, such as a training and inference loop, that trains badly, and find what is wrong. Others hand you a small modeling setup and a dataset in a live environment and ask you to improve it: fix the bugs, notice the class imbalance, change the training method and explain why it should help. A few ask for a deep learning framework, others for scikit-learn. Ask the recruiter which format and which libraries to expect.
Practise the round out loud
Mockich’s ML coding round runs 45 min: two problems at regular and one deeper at lead, in Python with NumPy and pandas, in an editor that runs your code. Vera asks for your plan and its complexity, reads what you wrote and the result, and gives at most three small nudges, never the answer. The report scores problem solving, code quality, complexity, testing and communication (plus production thinking at lead) and quotes what you said.
Sources
We read these public write-ups on 2026-11-02 (source 5 only up to its sign-in wall) and summarised where they agree, in our own words. Sources 1 and 2 are one practitioner and count as one voice; the detailed signal and failure lists come mostly from source 4. They report typical practice; no company publishes how it scores ML coding, and formats differ between companies and teams.
- [1] Yuan Meng, (Opinionated) Guide to ML Engineer Job Hunting
- [2] Yuan Meng, MLE Interview 2.0: Research Engineering and Scary Rounds
- [3] Brian Kihoon Lee (moderndescartes.com), Interviewing for ML/AI Engineers
- [4] PracHub, Machine Learning Coding Interview Questions: NumPy, Pandas, and Model Implementation
- [5] CalibreOS, ML Coding Interview: Implementing Algorithms From Scratch