← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026Remote

Summary

Meta research engineer screen, one meaty ML math question that was more derivation-heavy than I expected for a phone round. Not a vibe check at all.

Questions Asked (1)

Q1

Given a set of 2D points, derive the closed-form least-squares solution for the scalar weight w in the model y_hat = w * x (no intercept term). Walk through the derivation by differentiating the MSE with respect to w and setting it to zero, then implement it in code.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the answer but fumbled the derivation order a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining the model and the mean squared error (MSE) objective. Then derive the closed-form solution by taking the derivative of MSE with respect to w, setting it to zero, and solving for w. Finally, implement the formula in code, ensuring numerical stability and discussing edge cases.

Pro tip: Mention that the solution is equivalent to the dot product of x and y divided by the dot product of x with itself, and highlight that this is the projection of y onto the subspace spanned by x. Also, note that if all x values are zero, the denominator is zero, so w is undefined; in practice, handle this by returning 0 or raising an error.

1. Define the Model and Objective

State the model y_hat = w * x and the MSE loss function: L(w) = (1/n) * sum((y_i - w * x_i)^2).

2. Derive the Gradient

Differentiate L(w) with respect to w: dL/dw = (-2/n) * sum(x_i * (y_i - w * x_i)). Set this derivative to zero.

3. Solve for w

Rearrange the equation to isolate w: w = sum(x_i * y_i) / sum(x_i^2). This is the closed-form least-squares solution.

4. Implement in Code

Write a function that computes w using the formula, e.g., in Python: w = np.dot(x, y) / np.dot(x, x). Include handling for the case when sum(x_i^2) == 0.

5. Discuss Edge Cases and Extensions

Mention that if all x are zero, w is undefined; also note that this is a special case of linear regression without intercept, and the solution can be seen as the projection of y onto x.

Key Points to Mention

  • The MSE loss function and its derivative.
  • Setting the derivative to zero to find the minimum.
  • The closed-form solution w = (x·y) / (x·x).
  • The geometric interpretation as projecting y onto the line spanned by x.
  • Numerical stability considerations, such as avoiding division by zero.
  • Implementation details: using vectorized operations (e.g., NumPy) for efficiency.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.