Technical Interview Preparation for AI/ML Roles
๐ฏ Career Resources ยท Hope AI โ ML & DS Course
๐ฏ TL;DR โ This cheat sheet covers the exact format of AI/ML technical interviews at top companies, the 50 ML theory questions interviewers actually ask, system design frameworks for AI, and from-scratch coding problems โ with model answers.
| Company | Coding Round | ML Theory | System Design | Take-Home | Notes |
| Anthropic | Medium LeetCode | Heavy โ transformers, RLHF | LLM system design | Yes (ML project) | Focus on safety + reasoning |
| Google / DeepMind | Hard LeetCode | Strong ML fundamentals | Large-scale ML systems | Rare | Strong DSA required |
| Meta AI | Medium LeetCode | NLP + Recommendation systems | Feed ranking, ads ML | Rare | Practical + scale-focused |
| OpenAI | Medium LeetCode | LLM internals, training | LLM deployment | Sometimes | Reasoning ability weighted high |
| Startups (Series AโC) | EasyโMedium | Practical ML knowledge | Simple API + ML design | Often | Code quality + shipping speed |
| Indian product cos | Easy LeetCode | ML basics + Python | Not always | Sometimes | Strong Python + SQL expected |
๐ข Step-by-Step: How to Approach a Technical Interview
- Clarify โ Repeat the problem back, ask 1โ2 clarifying questions before coding.
- Plan out loud โ Explain your approach before writing a single line. Say: "My approach is X because Y."
- Start simple โ Write the brute-force solution first, then optimize. Never start with the most complex version.
- Test as you write โ Walk through an example with your own code before saying "done."
- Communicate trade-offs โ "This is O(nยฒ) time. We could improve it to O(n log n) with X, but I'll start here."
- Handle edge cases โ empty input, nulls, duplicates, very large inputs.
- Ask for feedback โ "Is this the direction you were looking for? Should I optimize further?"
๐ก Templates & Scripts
ML System Design Framework: "CRAP"
Use this structure for any ML system design question:
C โ Clarify the problem
โข What is the exact ML task? (classification, ranking, generation, retrieval)
โข What is scale? (QPS, users, data volume)
โข What are the latency constraints?
โข Online (real-time) or offline (batch)?
R โ Raw Data & Features
โข What data do we have? How is it collected and labeled?
โข What features matter most? How do we compute them at scale?
โข Feature store? Real-time vs precomputed?
A โ Algorithm & Model
โข Which model family fits? (classical ML, deep learning, LLM, retrieval)
โข How do we train? (full training, fine-tuning, prompting)
โข How do we evaluate offline? (metrics, holdout set, A/B test)
P โ Production & Monitoring
โข How do we serve? (API, batch, edge)
โข How do we handle model drift?
โข How do we roll back safely?
โข What are the failure modes?
Design a RAG System (Model Answer)
Clarify: Document Q&A for [use case]. Need <2s latency, 10K users.
Ingestion Pipeline:
โ Documents parsed (PyMuPDF / Docling)
โ Chunked (512 tokens, 10% overlap)
โ Embedded (text-embedding-3-small or all-MiniLM)
โ Stored in vector DB (ChromaDB for dev, Pinecone for prod)
Query Pipeline:
โ User query โ embed โ cosine similarity search โ top-K chunks retrieved
โ Chunks + query โ LLM prompt โ streamed response
Key Design Decisions:
โข Chunk size: 512 tokens balances context window vs. precision
โข Reranking: Add cross-encoder reranker after retrieval for accuracy
โข Metadata filtering: Filter by date/source before vector search
โข Hybrid search: BM25 + vector search (better than either alone)
Production:
โข Cache frequent queries (Redis)
โข Log queries + retrieved chunks for monitoring
โข Measure: retrieval precision, answer faithfulness (RAGAs framework)
โข Fallback: if confidence < threshold, say "I couldn't find this in the documents"
Design an LLM-Powered Chatbot (Model Answer)
Components:
1. Conversation memory: last N turns in context window (short-term),
summarized history in vector DB (long-term)
2. Tool use: web search, calculator, code execution (via function calling)
3. Safety layer: input filtering + output moderation
4. Response streaming: SSE or WebSockets for real-time feel
Serving: FastAPI โ Anthropic/OpenAI API โ SSE response โ React frontend
Scaling: Stateless API + session state in Redis. Rate limit per user.
Monitoring: Log all turns. Track: latency, token usage, user ratings.
From-Scratch Coding: K-Means (Python)
import numpy as np
def kmeans(X, k, max_iters=100):
# Initialize centroids randomly from data points
centroids = X[np.random.choice(len(X), k, replace=False)]
for _ in range(max_iters):
# Assign each point to nearest centroid
distances = np.linalg.norm(X[:, None] - centroids, axis=2)
labels = np.argmin(distances, axis=1)
# Update centroids
new_centroids = np.array([X[labels == i].mean(axis=0) for i in range(k)])
# Check for convergence
if np.allclose(centroids, new_centroids):
break
centroids = new_centroids
return labels, centroids
From-Scratch Coding: Gradient Descent (Python)
def gradient_descent(X, y, lr=0.01, epochs=1000):
m, n = X.shape
theta = np.zeros(n)
for _ in range(epochs):
predictions = X @ theta
errors = predictions - y
gradient = (X.T @ errors) / m
theta -= lr * gradient
return theta
From-Scratch Coding: Linear Regression with MSE
def linear_regression_fit(X, y):
# Closed-form: theta = (X^T X)^(-1) X^T y
return np.linalg.pinv(X.T @ X) @ X.T @ y
def predict(X, theta):
return X @ theta
def mse(y_true, y_pred):
return np.mean((y_true - y_pred) ** 2)
๐ค Practice Q&A โ Top 50 ML Theory Questions
ML Fundamentals (Must Know)
| Question | Model Answer (1โ3 lines) |
| Bias-variance trade-off | High bias = underfitting (too simple). High variance = overfitting (too complex). Goal: minimize both. Regularization reduces variance; more data / more complex model reduces bias. |
| What is gradient descent? | Optimization algorithm that iteratively moves model parameters in the direction that decreases loss. Step size = learning rate. |
| L1 vs L2 regularization? | L1 (Lasso) produces sparse weights (feature selection). L2 (Ridge) shrinks all weights. L1 good when you suspect many irrelevant features. |
| What is cross-validation? | Split data into K folds. Train on K-1, test on 1. Repeat K times. More reliable than single train/test split. |
| How do you handle imbalanced data? | Resample (oversample minority / undersample majority), use class weights, use precision-recall metrics instead of accuracy, try SMOTE. |
| What is data leakage? | When information from test/future data leaks into training. Fix: apply all preprocessing (scaling, encoding) inside the CV fold, never on the full dataset. |
| Precision vs Recall? | Precision = "of all predicted positives, how many are real?" Recall = "of all real positives, how many did I catch?" High recall for fraud/cancer detection. High precision for spam filters. |
| What is ROC-AUC? | AUC = area under the ROC curve. Measures model's ability to distinguish classes at all thresholds. AUC 0.5 = random, 1.0 = perfect. |
| How does Random Forest reduce variance? | Trains many decision trees on random data subsets with random feature subsets (bagging + feature randomness), then averages predictions. Variance cancels out. |
| What is XGBoost? | Gradient boosted trees โ each tree corrects errors of the previous. Faster and more regularized than vanilla gradient boosting. |
Deep Learning
| Question | Model Answer |
| What is backpropagation? | Algorithm to compute gradients of loss with respect to all parameters using the chain rule. Propagates error signal backward through the network. |
| What is the vanishing gradient problem? | Gradients become extremely small in early layers of deep networks (especially with sigmoid/tanh), making learning stall. Fixed by: ReLU, residual connections (ResNets), batch norm. |
| What is batch normalization? | Normalizes activations within each mini-batch. Speeds training, reduces sensitivity to initialization, acts as light regularizer. |
| What is dropout? | Randomly zeroes out neurons during training (e.g., 20% of neurons per forward pass). Forces redundancy, reduces overfitting. Disabled at inference. |
| CNN vs RNN? | CNN: good for local spatial/temporal patterns (images, short sequences). RNN: good for long sequences but struggles with long-range dependencies. Transformers now outperform both. |
NLP / LLMs
| Question | Model Answer |
| What is the transformer architecture? | Encoder-decoder (or decoder-only) architecture using self-attention. Each token attends to all other tokens. Parallelizable โ replaced RNNs for NLP. |
| What is self-attention? | Each token computes a weighted sum of all other tokens' values. Weights = softmax(QKแต/โd). Allows model to capture relationships between any two tokens regardless of distance. |
| BERT vs GPT? | BERT = encoder only, bidirectional, good for classification/understanding. GPT = decoder only, autoregressive, good for generation. |
| What is RLHF? | Reinforcement Learning from Human Feedback. Humans rank model outputs โ reward model trained on rankings โ LLM fine-tuned with RL to maximize reward. Makes models more helpful and safe. |
| What is RAG? | Retrieve relevant documents from a knowledge base at query time, inject them into the LLM prompt. Reduces hallucinations, enables up-to-date and private knowledge. |
| What is fine-tuning vs prompting? | Fine-tuning: updates model weights on new data (expensive, better for specialized tasks). Prompting: no weight update (cheap, good for general tasks). LoRA/QLoRA = parameter-efficient fine-tuning. |
| What is LoRA? | Low-Rank Adaptation โ instead of updating all weights, adds small trainable rank-decomposition matrices. 100x fewer parameters to train. Standard method for fine-tuning LLMs. |
AI Agents & RAG
| Question | Model Answer |
| What is the ReAct pattern? | Reasoning + Acting. LLM iterates: Think โ Act (call tool) โ Observe (see result) โ repeat. Allows multi-step problem solving. |
| What is LangGraph? | Framework for building stateful AI agent workflows as directed graphs. Each node is an agent/tool step. Good for multi-agent, branching, and loop-based workflows. |
| RAG vs fine-tuning โ when to use each? | RAG: when knowledge changes frequently or is large. Fine-tuning: when you need a specific style, format, or reasoning pattern baked into the model. |
| What is chunking strategy? | How you split documents for embedding. Key choices: chunk size (128โ1024 tokens), overlap (10โ20%), semantic vs. fixed-size splitting. Larger chunks = more context; smaller = more precision. |
โ ๏ธ Common Mistakes to Avoid
- Jumping to code without clarifying โ spend 2 minutes clarifying before writing anything
- Silence during thinking โ narrate your thought process, even when uncertain
- Only knowing theory, not implementation โ practice writing k-means, GD from scratch
- Ignoring system design โ companies at all levels now expect ML system design
- LeetCode Hard obsession โ most AI roles test Medium-level DSA; depth in ML matters more
- Not knowing your own resume projects โ expect deep follow-up on anything you listed
- Saying "I haven't used that" โ follow with "but here's how I'd approach learning/using it"
๐ Quick Reference: DSA Topics for AI Interviews
| Must Know | Nice to Know | Skip (for AI roles) |
| Arrays, strings, hash maps | Trees and graphs (BFS/DFS) | Advanced graph algorithms |
| Sorting (merge sort, quick sort) | Two pointers, sliding window | Segment trees, Fenwick trees |
| Binary search | Dynamic programming (basic) | Bit manipulation |
| Recursion | Heap / priority queue | Advanced DP |
Target: 30 LeetCode Mediums + 10 Easys before interviews. Track in a spreadsheet.
๐ Action Checklist
- Memorize the CRAP framework and apply it to 3 system design questions
- Answer all 10 ML Fundamentals questions without looking at answers
- Implement K-Means, Gradient Descent, and Linear Regression from scratch (no libraries)
- Design a RAG system on paper โ draw the architecture diagram
- Complete 20 LeetCode Easy/Medium problems (focus: arrays, hash maps, binary search)
- Do one timed mock interview with a friend (45 minutes, whiteboard-style)
- Study transformer architecture until you can explain self-attention in 60 seconds
- Research the specific interview style of your top 3 target companies