Yahoo logoYahoo
Coding·60 minFree preview

Rank Items by Embedding Similarity in NumPy

Given one user embedding and N item embeddings, score each item by dot product with the user vector, then return item indices sorted by score from high to low. Follow-up: drop items the user has already seen from the final ranking. NumPy is required; the whole solution is under ten lines.

RS
numpy
ranking
recommendation
sorting
easy
Frequency
Single report
Last asked
2026-10-08
Stage
phone-screen

Problem

Written in NumPy during the 60-minute Yahoo Mail research-scientist phone screen, which pairs this exercise with ML fundamentals questions.

  • Input: one user embedding vector and N item embedding vectors.
  • Scoring: the similarity score of an item is the dot product of the user embedding and that item's embedding.
  • Output: the list of item indices sorted by score from highest to lowest.

Pitfalls

  • Searching the web is not allowed during the round. If you forget NumPy syntax, the interviewer is fine with you explaining the idea and asking for the exact call, but fluent NumPy saves time.
  • The output is item indices ordered by score, not the sorted scores themselves.

Follow-ups

Preparation

  • Drill the core NumPy calls from memory: matrix–vector product (@ / np.dot), np.argsort with descending order, boolean masks and np.isin for filtering.
  • Write the full score → sort → filter pipeline end to end without looking anything up, then explain the shape of every intermediate array aloud.
  • Be ready to discuss how the same pattern scales to a real retrieval setting (many users at once, large N).
Was this article helpful?

Comments

Sign in to join the discussion
Loading...