← LinkedIn Interview Insights

LinkedIn·AI Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

LinkedIn AI Engineer interview with a machine learning system design question centered on collaborative filtering. The problem was more implementation-heavy than I expected, pushing into data structure territory pretty quickly.

Questions Asked (1)

Q1

Given a sparse user-movie rating matrix, how would you use kNN to predict a target user's rating for a movie they haven't seen? Walk through your similarity metric choice, neighbor selection, and the data structures you'd use to make it efficient.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I started with cosine similarity because it felt safer than Pearson and I could explain it faster under pressure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the problem as a user-based collaborative filtering task, then systematically address similarity metric, neighbor selection, and efficient data structures. Emphasize how sparsity impacts each choice and propose practical solutions like shrinkage and approximate nearest neighbor search.

Pro tip: Mention that in production systems like LinkedIn, you'd likely combine kNN with matrix factorization or use approximate methods (e.g., LSH, HNSW) to handle scale, and always validate offline with ranking metrics like NDCG.

1. Define the prediction task

Clarify that you're predicting a missing rating for a target user-movie pair using user-based kNN: find similar users who rated the movie, then aggregate their ratings.

2. Choose similarity metric

Select a metric robust to sparsity, such as cosine similarity on mean-centered ratings or Pearson correlation. Discuss handling missing values and significance weighting.

3. Select neighbors

Decide on k (e.g., 20-50) and consider only users who rated the target movie. Optionally use a similarity threshold or weighted voting to reduce noise.

4. Aggregate ratings

Predict the rating as a weighted average of neighbor ratings, using similarities as weights. Optionally adjust for user rating bias (e.g., add target user's mean rating).

5. Design efficient data structures

Store ratings in a sparse matrix (CSR/CSC) for fast access. Precompute user-user similarities or use approximate nearest neighbor indexes (e.g., LSH, HNSW) to avoid O(n^2) computation.

Key Points to Mention

  • Sparsity challenges: many missing ratings, so similarity computation must handle unrated items (e.g., only consider co-rated items).
  • Similarity metrics: cosine similarity, Pearson correlation, and adjustments like mean-centering and significance weighting.
  • Neighbor selection: choosing k, using similarity thresholds, and ensuring neighbors have rated the target item.
  • Prediction aggregation: weighted average, possibly with baseline predictors (user/item biases).
  • Efficiency: sparse matrix representations (CSR/CSC), inverted indices for co-rated items, and approximate nearest neighbor search for scalability.
  • Evaluation: offline metrics like RMSE, MAE, and ranking metrics (e.g., NDCG) for implicit feedback scenarios.

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