Fix and Improve recommend(user) in a Friend Recommendation Codebase

Quick Overview

A coding exercise on an existing friend recommendation codebase: fix a recommend(user) method that suggests users to themselves, build an improved version that ranks candidates by friend-circle overlap, and explain how to evaluate it. It tests debugging, graph-based ranking, complexity analysis and recommendation metrics.

Fix and Improve recommend(user) in a Friend Recommendation Codebase

Company: Fireworks

Role: Machine Learning Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

You are given an existing code repository that implements a friend recommendation system for a social network. Its main entry point is a `recommend(user)` method that returns people the user may want to add as friends. You may use most common AI coding tools (for example Codex, Claude Opus or Gemini) throughout the session. The interviewer asks for three things in order: make a failing test pass, write an improved `recommend(user)`, and explain how you would evaluate it. In the reported interview, ranking candidates by how much their friend circle overlaps with the user's friend circle was accepted, and the interviewer added no further requirements. The repository itself is not reproduced here. Assume it stores friendships as an undirected graph (a mapping from each user id to the set of that user's friends) and that `recommend(user)` returns a ranked list of user ids. Say where your answer depends on these assumptions. ### Clarifying Questions - Is friendship mutual in the data model, or can one user list another as a friend without the reverse? - How many recommendations should `recommend(user)` return? - Besides the user, should people who are already the user's friends be excluded? - What should the method return for a user with no friends, or for a user id that does not exist? - How should candidates with equal scores be ordered, so that test results are deterministic? - Does "performance" in the evaluation step mean recommendation quality, running time, or both? ### Part 1: Make the failing test pass An existing test for `recommend(user)` fails because the method can recommend a user to themselves. Find the cause and change the code so the test passes. ```hint Trace a candidate's path Follow the route the code takes from the user to each candidate, and ask which step of that route can lead back to the starting user. ``` #### What This Part Should Cover - The root cause in how candidates are generated. - Where the fix belongs, with the test left unchanged. - Whether the same flaw lets other invalid candidates through. - Regression tests that pin the corrected behavior. ### Part 2: Implement an improved recommend(user) Design and implement a new, improved `recommend(user)`. Explain how candidates are found, how they are scored and ordered, and what a call costs. ```hint Weigh the overlap Decide whether a raw count of shared friends is enough, or whether a shared friend who has thousands of friends should count as much as one who has twenty. ``` #### What This Part Should Cover - A candidate set built from the graph, with the exclusions from Part 1. - A scoring rule for friend-circle overlap and a deterministic tie rule. - Time and memory cost, including users connected to accounts with very many friends. - Tests for ranking order and edge cases. ### Part 3: Evaluate recommend(user) How would you evaluate the performance of `recommend(user)`? Which metrics would you use, and how would you measure them? ```hint Where ground truth comes from Offline evaluation needs known answers. Think about which friendships in data you already have could serve as answers without the method seeing them first. ``` #### What This Part Should Cover - Offline quality metrics, and how the held-out friendships are chosen. - Online metrics once real users see the recommendations. - Running time and resource use per call. - Comparison against a simple baseline. ### What a Strong Answer Covers - A fix at the cause in the code under test, verified by running the suite. - Correct, deterministic ranking code with its complexity stated. - Evaluation metrics that measure the product outcome: friend requests sent and accepted. - Careful use of AI tools: generated changes are read, explained and tested before they are kept. ### Follow-up Questions - An account has millions of friends. How does your method behave when that account is a mutual friend, and when it is the user asking for recommendations? - How would you recommend friends to a new user who has no friends yet? - Offline precision improves, but the share of sent friend requests that get accepted drops after launch. What could explain it? - How would you precompute recommendations for every user in a nightly batch, and keep them fresh as new friendships form during the day?

Overview: A coding exercise on an existing friend recommendation codebase: fix a recommend(user) method that suggests users to themselves, build an improved version that ranks candidates by friend-circle overlap, and explain how to evaluate it. It tests debugging, graph-based ranking, complexity analysis and recommendation metrics.

Read the full Fireworks Machine Learning Engineer interview experience this question came from

Fireworks logo
Fireworks
Nov 24, 2026
mediumMachine Learning EngineerTechnical ScreenSoftware Engineering Fundamentals
0
0

You are given an existing code repository that implements a friend recommendation system for a social network. Its main entry point is a recommend(user) method that returns people the user may want to add as friends. You may use most common AI coding tools (for example Codex, Claude Opus or Gemini) throughout the session.

The interviewer asks for three things in order: make a failing test pass, write an improved recommend(user), and explain how you would evaluate it. In the reported interview, ranking candidates by how much their friend circle overlaps with the user's friend circle was accepted, and the interviewer added no further requirements.

The repository itself is not reproduced here. Assume it stores friendships as an undirected graph (a mapping from each user id to the set of that user's friends) and that recommend(user) returns a ranked list of user ids. Say where your answer depends on these assumptions.

Clarifying Questions Guidance

  • Is friendship mutual in the data model, or can one user list another as a friend without the reverse?
  • How many recommendations should recommend(user) return?
  • Besides the user, should people who are already the user's friends be excluded?
  • What should the method return for a user with no friends, or for a user id that does not exist?
  • How should candidates with equal scores be ordered, so that test results are deterministic?
  • Does "performance" in the evaluation step mean recommendation quality, running time, or both?

Part 1: Make the failing test pass

An existing test for recommend(user) fails because the method can recommend a user to themselves. Find the cause and change the code so the test passes.

What This Part Should Cover Guidance

  • The root cause in how candidates are generated.
  • Where the fix belongs, with the test left unchanged.
  • Whether the same flaw lets other invalid candidates through.
  • Regression tests that pin the corrected behavior.

Part 2: Implement an improved recommend(user)

Design and implement a new, improved recommend(user). Explain how candidates are found, how they are scored and ordered, and what a call costs.

What This Part Should Cover Guidance

  • A candidate set built from the graph, with the exclusions from Part 1.
  • A scoring rule for friend-circle overlap and a deterministic tie rule.
  • Time and memory cost, including users connected to accounts with very many friends.
  • Tests for ranking order and edge cases.

Part 3: Evaluate recommend(user)

How would you evaluate the performance of recommend(user)? Which metrics would you use, and how would you measure them?

What This Part Should Cover Guidance

  • Offline quality metrics, and how the held-out friendships are chosen.
  • Online metrics once real users see the recommendations.
  • Running time and resource use per call.
  • Comparison against a simple baseline.

What a Strong Answer Covers Guidance

  • A fix at the cause in the code under test, verified by running the suite.
  • Correct, deterministic ranking code with its complexity stated.
  • Evaluation metrics that measure the product outcome: friend requests sent and accepted.
  • Careful use of AI tools: generated changes are read, explained and tested before they are kept.

Follow-up Questions Guidance

  • An account has millions of friends. How does your method behave when that account is a mutual friend, and when it is the user asking for recommendations?
  • How would you recommend friends to a new user who has no friends yet?
  • Offline precision improves, but the share of sent friend requests that get accepted drops after launch. What could explain it?
  • How would you precompute recommendations for every user in a nightly batch, and keep them fresh as new friendships form during the day?