AI Interviews · Question

AI-allowed onsite coding: recommend users to a given user from the friendship graph by mutual friends, never recommending current friends, then return a bounded score in [0, 1] for each recommendation.

AI-assisted coding question reported at Fireworks AI (Sep 2026). Sources, confidence and an answer card.

Researched · updated

r2a-025 Both tracks AI-assisted coding rounds AI-assisted coding Medium confidence
On this page

What they’re really asking

If you only remember one thing, say this in the first minute: “I’ll find candidates as friends of friends, counting mutual friends, and never include the user or anyone they’re already friends with. For the score in [0, 1], I’ll use Jaccard similarity: mutual friends divided by everyone either of them knows. It stays between 0 and 1 and doesn’t let very popular users win just by being popular. The assistant can write the graph code and tests; I’ll write or check the scoring line myself against a small example worked by hand.”

The rest of this page explains each part of that answer.

The question wants correct graph code plus a scoring decision you can defend.

In a normal coding round, there is one right answer and the tests know it. The second step here has several right answers. Many formulas give a score between 0 and 1, and each one rewards something different. The interviewer wants to hear you choose and say why. An assistant (a chat tool backed by a large language model, or LLM: a program trained on huge amounts of text and code that writes a plausible reply to what you type) will happily produce a bounded score. It won’t tell you what that score rewards. That part is yours.

A Fireworks AI machine-learning engineer onsite report describes AI-allowed coding: recommend users to a given user by mutual friends, never recommending current friends, then return a bounded score in [0, 1] for each recommendation (PracHubfirst-hand · 13 Sep 2026). The post is short and the outcome isn’t stated.

Clarify first

  • Are friendships two-way? Assume yes (undirected).
  • Top k, and tie-breaking? Assume top 10, ties broken by user id.
  • Exclusions. The user and existing friends; also blocked users, if the data has them.
  • What the score is for. Ranking only, or a probability-like number shown to someone? That decides how to normalize it.
  • Graph size, for complexity.

Answer

Words you need first

  • N(x): the set of x’s friends. Degree is the size of that set.
  • Mutual friends: N(u) ∩ N(v), people in both sets.
  • Normalize: divide a raw count by something, so the result lands in a fixed range like [0, 1].
  • Jaccard similarity: mutual friends ÷ everyone in either friend list, |N(u) ∩ N(v)| ÷ |N(u) ∪ N(v)|.
  • Overlap coefficient: mutual friends ÷ the smaller of the two friend lists.

Candidates and mutual counts

For user u: for each friend f, for each friend v of f, skip u and u’s friends, and add one to mutual[v]. The cost is the sum of the friends’ degrees: about d × d set checks for an average degree d.

The worked example: five users, two scores

   1 ─── 2
   │     │
   3 ─── 4
   │
   5

Friendships: 1–2, 1–3, 2–4, 3–4, 3–5. Recommend for user 1, whose friends are {2, 3}:

CandidateTheir friendsMutual with user 1JaccardOverlapWhat to say in the interview
4{2, 3}{2, 3}: 22 ÷ 2 = 1.02 ÷ 2 = 1.0”Shares every friend. Both scores agree.”
5{3}{3}: 11 ÷ 2 = 0.51 ÷ 1 = 1.0”Overlap ties 5 with 4, because 5 has only one friend. Jaccard doesn’t.”

Users 2 and 3 never appear, because they are already friends, and user 1 never recommends themself. That table is your first test.

Candidate 5 is the teaching case. The overlap score says “everyone 5 knows, user 1 also knows”, which is true but based on a single friend. Jaccard says “they share half of their combined circle”. For a ranking, Jaccard usually reads better.

A bounded score: pick one and say why

Both scores are in [0, 1]. Jaccard penalizes very popular candidates, which is often what you want: someone with 2,000 friends shares a few with almost everyone. Overlap rewards a candidate who shares most of a small friend list, like user 5 above. A third choice, dividing the raw count by the largest count in this user’s list, is also bounded, but only meaningful within one user’s results.

Say it like this: “I’ll use Jaccard. It stays in [0, 1], and a celebrity doesn’t top everyone’s list just for being popular. If you want new users with few friends to surface, overlap is the alternative.”

Edge case: a user with no friends yields no candidates, so there is no division by zero. Guard it anyway; the next version of the code may call the scorer from somewhere else.

The arithmetic behind the numbers (for a Staff-level follow-up)
Two bounded scores
jaccard(u, v) = |N(u) ∩ N(v)| ÷ |N(u) ∪ N(v)|     overlap(u, v) = |N(u) ∩ N(v)| ÷ min(|N(u)|, |N(v)|)
N(x)
the friend set of user x
∩, ∪
mutual friends; friends of either
Worked example

u has 10 friends, v has 40, 5 are mutual: jaccard = 5 ÷ (10 + 40 − 5) = 0.11; overlap = 5 ÷ 10 = 0.5.

  • Why both stay in [0, 1]: the mutual set is never bigger than the union, and never bigger than the smaller list, so each ratio is at most 1. Neither can be negative.
  • The union without building it: |N(u) ∪ N(v)| = |N(u)| + |N(v)| − mutual, so Jaccard needs only the two degrees and the mutual count you already have.

Use the assistant for the checkable parts

Let it write the adjacency builder, the top-k with ties, and the tests. Write the scoring line yourself, or check it against the formula on the five-user example and on the 10 / 40 / 5 example in the box. Test that:

  • no current friend and not the user appears;
  • every score stays in [0, 1];
  • the order matches the hand-worked graph.

Senior vs Staff

Bounded recommendation score

Senior

  • Implements mutual-friend candidates correctly, chooses a bounded score, and tests the bounds and exclusions.

Staff

  • Explains what each normalization rewards, how to check the choice offline (did recommended pairs later connect?), and how high-degree users affect cost.

Small-team version

Bounded scores matter whenever a number leaves your code: a threshold in a product rule, a value shown in a UI, an input to another model.

  • Write the reason next to the code. At a small company the person who picks the normalization usually has to justify it to product too. One comment line saves a meeting.
  • Check offline before tuning. Take last month’s data, score the pairs, and see whether high-scoring pairs actually connected later. That is a database query, not a new system.
  • Compute it in a batch job. A nightly job over the friendship table is enough until recommendations must react within seconds.

Pitfalls

  • Recommending existing friends or the user. The five-user table catches both.
  • A “score” that can exceed 1, or divides by zero. Raw counts aren’t bounded; an empty friend list has nothing to divide by.
  • Choosing a normalization without saying what it rewards. That explanation is the second half of the question.
  • Trusting generated scoring code without a hand-worked example. One wrong denominator still produces numbers that look fine.

Go deeper

Family

AI-assisted coding round in a provided codebase

Meta-style rounds (and their Microsoft, OpenAI, Apple and Fireworks cousins): fix a bug, build a feature and make it faster in a repo you've never seen, with an AI assistant you direct, check and sometimes overrule.

Other questions in this family