Skip to content
LeetCode will be flattened out, but mathematics won't

LeetCode will be flattened out, but mathematics won't

I recently helped someone with a mock interview. Five medium-difficulty problems; he finished four in twenty minutes, with clean handling of edge cases.

Then I asked a question that wasn’t from any question bank: why does cross-entropy loss get especially large when a model confidently answers wrong.

He paused for a long time, then said, I’ve memorized the formula, but I’ve never thought about it from that angle.

That pause said more than the previous twenty minutes. It wasn’t that his fundamentals were weak—it was that he’d never been asked to connect formulas to model behavior. And that’s exactly the kind of question that’s becoming more common in interviews.

The discriminative power of question banks is thinning

Standard algorithm problems are in a somewhat awkward position.

On the candidate side, templates and solutions are public, and AI completion is faster than most people can write by hand. On the interviewer side, what a forty-five-minute whiteboard problem can verify is getting narrower: whether you can write code with correct edge cases under pressure, whether you can articulate complexity clearly. These two things still matter, but they increasingly fail to represent a person’s ability to handle real problems.

So problems are shifting in two directions. One is coding problems with tools—documentation lookup allowed, assistants allowed—but with follow-ups on why you chose this approach, how you’d detect that a generated implementation has degraded in complexity, and what tests you’d add to prove it’s correct. The other is code reading and troubleshooting: give a piece of code that runs but hides problems, and ask for localization, explanation, a minimal fix, and then a judgment on the side effects of that fix.

The more obvious change is that many teams now ask conceptual questions before writing code. Three to five fundamental questions in a row; if you can’t answer, there’s no point continuing. For candidates this is a bit cruel, because these questions have no standard question bank, and cramming is hard to compensate for.

I don’t think algorithm problems and engineering ability are opposed. Someone who can write a medium problem cleanly usually isn’t too bad at variable naming, edge-case handling, or debugging habits either. The problem is only that these problems have been treated as the sole screening criterion. Put someone who can only solve problems and has never touched a system next to someone who has built systems and is average at problems, and the latter is less trouble in most roles.

This isn’t interviewers deliberately making things hard. Real work is like this: most of the time goes to reading other people’s code, taking over existing systems, and judging whether a result that looks right is actually right. Reciting templates is the least-used skill of all.

But LeetCode hasn’t disappeared; it has retreated to the position of infrastructure. Like a fitness test—it doesn’t mean you can play ball, but if your fitness is too poor, you can’t last on the court. Many companies’ processes won’t be immediately restructured because of this judgment either; the algorithm round is still a standard stage, only the weighting afterward has changed.

My judgment is: being able to consistently pass medium problems is enough; there’s no need to grind to competitive-programming level. Being able to write a solution with correct edge cases and clear complexity within an hour is enough, and the remaining time should go elsewhere. Completely ignoring algorithm problems doesn’t work either—some processes won’t even reach the later rounds.

My own preparation approach has changed too. I used to fixate on problem volume; now I maintain feel: two or three medium problems a week, timed, and after finishing, verbally walk through the approach and complexity. The rest of the time goes to reading other people’s training code, guessing where it will break, then running it to verify. The latter is more tiring, but closer to real work.

One more thing to be clear about: I don’t think everyone needs to fill in the same set of math. For business development, filling in intuition for probability and statistics is enough; for model training, optimization and information theory are unavoidable; for infrastructure, linear algebra and numerical stability matter more. Tailoring to the role is far more realistic than studying from a book list from the beginning. What really creates separation in interviews is often not how much you’ve studied, but whether you can land what you’ve studied on a concrete problem.

Five kinds of math, each handling one thing

If you only remember one sentence: probability handles uncertainty, information theory quantifies it; linear algebra and optimization handle how the model is represented and trained; statistical learning answers whether it actually learned anything.

Probability is the most easily underestimated. Most people will say conditional probability and Bayes’ formula, but what interviewers really want to hear is: can you clearly explain “how belief changes after seeing evidence.” The classic spam example—computing 0.75 isn’t hard; what’s hard is adding that this word pushed the posterior from 20% to 75%, and that’s the update.

Naive Bayes’ independence assumption almost never holds, yet it’s still useful. The reason is that it compresses estimation difficulty to an acceptable level: few parameters, fast training, stable on small data. This is a typical engineering trade-off—exchanging a wrong assumption for a usable model. Being able to clearly explain “where the assumption is wrong and why it still works” is worth more in an interview than reciting formulas.

Another use of Bayes is troubleshooting. When some metric drops online, the prior is “probably a data problem”; after seeing the missing rate of some feature spike, the posterior should shift toward the data pipeline. This way of thinking is more commonly used than the formula itself: start with an initial judgment, then let evidence revise it by weight, rather than guessing from scratch every time.

Expectation and variance are also often treated as calculation problems. What’s really useful is that binary-classification conclusion: the variance of predicted probability p is p(1-p), maximal when p is near 0.5. This explains a very practical phenomenon—boundary samples are hard to judge not because the model is dumb, but because such samples inherently carry little information. When setting thresholds, doing risk control, or scheduling manual review, this intuition is worth more than the formula.

Expectation problems are also often packaged as business problems. Two strategies: one with high click-through but low conversion, one with low click-through but high order value—which to choose. The correct approach isn’t to compare single metrics, but to define a random variable, multiply by payoff, and compute expectation. Many people get stuck here not because they can’t calculate, but because they haven’t developed the habit of “first translating metrics into payoff.”

Information theory is the watershed. Entropy, information gain, KL divergence—the formulas aren’t long, but few people can connect them to models. The asymmetry of KL is more revealing than the formula itself about whether you’ve thought about it: using Q to approximate P and using P to approximate Q are not the same cost. Where P has high probability and Q gives too little, the penalty is heavy; conversely, when Q captures one peak and drops other modes, it’s sometimes “cheaper.” This difference isn’t mathematical pedantry; it directly affects whether, in variational methods, the model tends to cover or tends to converge to a single mode.

Computing it once with two distributions is more useful than reading the definition ten times. Let P be (0.9, 0.1) and Q be (0.5, 0.5); the KL from the former to the latter is about 0.37, and the reverse is about 0.51. The difference isn’t large, but the direction is already different. This asymmetry isn’t a detail; it determines whether, when uncertain, the model tends to cover all possibilities or bets on the most likely one.

On the decision tree side, information gain and Gini do the same thing, just with different measures. Entropy involves a logarithm and its explanation is closer to information theory; Gini doesn’t involve a logarithm, computes faster, and usually gives similar conclusions. The two criteria have no right or wrong, only implementation preference.

There’s another relationship worth clarifying: cross-entropy equals the entropy of the true distribution plus KL divergence. When the true distribution is fixed, entropy is a constant, so minimizing cross-entropy is pulling the predicted distribution toward the true distribution. That phrase “minimize cross-entropy” during language model training essentially means this. Knowledge distillation uses the same logic, only replacing the true distribution with the teacher model’s output distribution, because soft labels preserve the relative relationships between classes.

Information gain has a pitfall that few people proactively mention in interviews: it favors features with many values. An ID that can almost group each sample separately will give very high purity on the training set, but generalize poorly. That’s why C4.5 introduced gain ratio. Being able to say this shows you’re not just remembering “the larger the information gain, the better.”

Linear algebra, by contrast, is less about derivations. Matrix multiplication in neural networks isn’t arithmetic—it’s a spatial mapping: each column of a weight matrix can be seen as a learnable feature detector, and the input combines with these directions to produce a new representation. Once this is clear, a shape error is no longer a syntax problem but a failure to understand the relationship between input space, output space, and parameter dimensions.

In interviews I give the shape of a two-layer network and ask the candidate to label each layer’s dimensions. It’s a tedious exercise, but it reveals whether they’ve actually thought through the computation. The inner dimensions of matrix multiplication must match—this isn’t a framework limitation, it’s the definition itself. People who can’t explain this usually get their code running by trial and error, and it breaks the moment they change a layer.

One level up is eigendecomposition and SVD. They answer “which directions in the data matter more.” PCA works for dimensionality reduction because the data cloud varies most along certain directions, and keeping the top principal directions preserves most of the variance. In engineering, SVD is more commonly used because real data matrices are often not symmetric square matrices, and SVD holds for any matrix. Anyone who has compressed embeddings has felt this: many of the dimensions you delete really were just amplifying noise.

Attention speaks the same language. Query and key are dot-producted to get similarity, softmax normalizes it into weights, and value is weighted-summed. Strip it down and it’s finding relevant directions in a vector space. People who can explain this clearly can usually also explain offhand why embeddings need normalization and why retrieval often uses cosine similarity rather than Euclidean distance.

Optimization tests training behavior. The gradient gives direction, the learning rate gives step size. Too small and learning is slow; too large and it bounces across the valley floor; larger still and it diverges. Vanishing gradients in deep networks are essentially repeated multiplication: each layer multiplies by a factor less than 1, so by the time it propagates back it approaches zero. This explanation is more useful than memorizing the phrase “vanishing gradient” because it also points to where the fixes are: change the activation, add residuals, change the initialization.

Backpropagation deserves its own note. Its efficiency isn’t because the formulas are elegant—it’s because it reuses the forward pass’s intermediate results, bringing gradient computation down to the same order as the forward pass. Without this, training large models would be impossible. Once you understand this, the differences between optimizers stop being mysterious: SGD is simple but jittery, Momentum adds inertia, Adam gives each parameter an adaptive step size. Adam is usually easier to train, but doesn’t necessarily win on final generalization—that’s a tradeoff, not a ranking.

Another commonly asked point: why can’t you compute gradients with numerical differentiation. Once the parameter count is large, every parameter needs a forward pass, and the cost explodes. Backpropagation reuses the forward pass’s intermediate results and makes one backward pass to get all gradients. The efficiency difference isn’t a constant factor—it’s the difference between being trainable and not.

The learning rate is the parameter I adjust most often when debugging. Too large and the loss oscillates within the first few steps; too small and it looks like it’s learning but barely moves. Whether to use warmup, whether to adjust it when batch size changes—these rules of thumb are in the books, but feel and judgment only come from running it yourself.

I compress training troubleshooting into an order: first look at the data—are labels misaligned, are features normalized, is the batch empty; then look at the forward pass—output shapes, activation functions, whether the loss input is reasonable; then look at the backward pass—are gradients all zero, are there NaNs, is the gradient norm abnormal; finally look at optimization—learning rate, whether gradients are cleared, whether step is actually called. This order has saved me many times, because it turns “the model won’t converge” from mysticism into a layer-by-layer process of elimination.

Class imbalance is also a frequent question. Accuracy is meaningless on such data, because predicting everything as the negative class can still yield a high score. Here you look at recall, at AUC, at the business cost under different thresholds. People who proactively say “first check whether the business fears false positives or false negatives more” are usually closer to being useful than those who recite metric definitions.

The bias-variance tradeoff isn’t a theoretical question either. As model complexity rises, bias falls and variance rises; as data volume rises, variance falls. The real difficulty is judging which side you’re stuck on. My experience: first look at the gap between training and validation, then look at how that gap changes with data volume. If adding data narrows the gap, it’s mostly a variance problem; if both are bad, it’s mostly a bias problem.

Statistical learning ties it together. High bias means the model is too dumb, high variance means it’s too sensitive, and generalization means whether it still works on a fresh batch of data. Training 99%, test 82%—saying “overfitting” is just a passing grade. What matters more is suspecting the evaluation itself first: is the split random, is there data leakage, are the class distributions on both sides consistent. Only then discuss model complexity and regularization.

The most common misjudgment I’ve seen in real projects is using offline metrics to explain online problems. Offline AUC went up but online bad-debt rate didn’t fall—the cause might be a change in sample definition, or an approval policy adjusted in the same period. Math itself can’t answer these questions, but without math you don’t even know which layer to suspect.

Distribution drift is another commonly overlooked point. Good performance during training that slowly degrades after launch is often not model degradation but a change in traffic. Tuning the model won’t help here—first look at feature distributions and time windows. My habit now is to add monitoring to key features, and when drift exceeds a threshold, check the data pipeline first rather than retraining. Retraining is fast, but it only records the new distribution; it doesn’t solve why it changed.

How I Would Ask

If I were interviewing for an AI-related role, I’d probably ask only three questions and follow the answers downward.

First: training loss won’t go down—in what order do you investigate.

What I want to hear isn’t “tune the learning rate” but whether there’s a layered awareness. The data layer’s labels and normalization, the forward layer’s shapes and loss input, the backward layer’s all-zero gradients and NaNs, the optimization layer’s forgotten gradient clearing and whether step is actually called. People who can walk this order have mostly actually run training.

I’d also follow up: if you can’t even overfit toy data, what does that tell you. This one is harsh, because it pulls the problem back from “the model isn’t strong enough” to “there’s a bug in the pipeline.” People who can answer it have usually stepped on it themselves.

Second: offline AUC is high, but after launch the bad-debt rate goes up instead—how do you investigate.

There’s no standard answer to this one; what I want to see is whether they suspect the definitions first. Did the sample definition change, are labels delayed, are training and online the same population, was the approval policy changed in the same period. People who only say “model drift” usually haven’t been on a real pipeline.

Third: why isn’t KL divergence a distance.

This one is cheap but very useful. Being able to say it’s asymmetric shows they’ve at least derived it once; being able to then explain the impact on optimization behavior shows they’ve thought about it.

Occasionally I add a fourth: if you could keep only one metric, which one. The answer itself doesn’t matter; what matters is whether they ask about the business goal first. Risk control keeps recall, marketing keeps response rate, content might keep dwell time. People who say “it depends” and can specify which case are usually more reliable than those who recite standard answers.

Conversely, I have my own moments of not being able to answer. I can’t remember the full derivation of variational inference—by the third line of expanding the ELBO I start to get fuzzy. My approach is to say outright that I can’t remember, then explain the intuition: approximate a complex posterior with a simple distribution, and constrain the approximation error with KL. Most interviewers accept this honesty, because they probably couldn’t derive it either.

After an interview, I note three things: whether the candidate proactively clarified assumptions, whether they stated their boundaries when they couldn’t answer, and whether they grounded their answers in concrete scenarios. Technical details can be filled in later; these three things are hard to fill in. Conversely, someone who answers every question like a textbook makes me worry they’ve never worked on a real system.

I also do mock interviews, but the focus isn’t on getting the answer right—it’s on practicing the pause. In a real interview, thinking for three seconds before answering is better than blurting something out, especially on uncertain questions. I have the person practice saying “I’m not sure, but my approach would be” until it comes out smoothly, because in the room that phrase is more useful than any technique.

I don’t really believe in “perfect answers.” Someone who can clearly state their boundaries and pause where they’re uncertain is more reliable than someone who answers every question smoothly. With the former, you can see where their knowledge ends; with the latter, you often only find out after they’re on the job.

My own practice method is pretty dumb. I take a toy sample with two or three numbers and hand-compute the gradient, then verify it with a few lines of code; I run a small model and deliberately crank up the learning rate to watch the loss explode; I compute cross-entropy and KL separately to confirm the difference is exactly the entropy. These actions don’t produce anything, but they turn formulas into observable phenomena.

I don’t really like the word “moat”

Math is a foundational language, not a moat. The value of a language lies in what you can explain with it, not in others being unable to speak it.

I’ve seen people who are great at math but bad at building models, and people who are average at math but extremely fast at debugging. The latter’s advantage comes from something else: they know where a seemingly correct answer might be wrong, and they’re willing to verify it. That kind of judgment isn’t built by grinding practice problems—it grows out of model failures, mismatched metrics, and production rollbacks, time after time.

I also don’t think math alone constitutes a barrier. It’s more like a threshold: many people can’t get past it, but once you’re through, everyone’s about the same. What really separates people is what comes after: whether you’ve taken a system from data to launch, whether you kept digging for three days when the metrics wouldn’t move, whether you found a data pipeline bug when everyone was saying “that’s just how the model is.”

Beyond math there’s another layer: taste. Which metric to choose, how much error to accept, when to stop optimizing—none of these have formulas. They come from judgment formed after doing enough projects. It’s hard to test directly in an interview, but you can see it after three months of working together.

These things are related to math, but the core is whether you’re willing to take responsibility for uncertainty. Math provides the language, engineering provides the evidence, and ultimately a person makes the judgment.

I’m also not sure how long this advantage will last. AI already explains KL, explains bias-variance, more clearly than I do. Once it can reliably pinpoint even “why won’t this training code overfit even on toy data,” what interviews test will change again.

So I’m not too worried about AI solving math problems. The faster it does, the more it shows that memorizing formulas is worthless. What’s valuable is knowing which formula to use, whether its preconditions hold, and which step to suspect first when results don’t match expectations. These require someone to take responsibility for the outcome.

What won’t change in the short term is something else: when a model gives an answer that looks right, people who can tell where it’s wrong are still scarce. That ability requires math, but not only math. It also requires having personally broken things and remembering how they broke.

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Algorithm Interviews #Mathematical Foundations #Model Judgment

Comments