Reported September 2026
Fireworks AIhash table

Mutual-Friend Referral Recommendations

Reported by candidates from Fireworks AI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Fireworks AI OA. Under 2s to a working solution.
Founder's read

Fireworks AI reported this one in September 2026, and the detail that matters is the score: m / d, where d is the target user's friend count. It's a friends-of-friends recommender dressed up with an NDCG footnote that changes nothing. If your OA invite lands soon, this is a hash-table and counting problem on an adjacency list, then a sort and a format step. It's not hard, but the rounding and tie-break details cost people tests. If you blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and gives you the solution live. Know the shape first and you probably won't need it.

The problem

An undirected graph contains users 0 through n - 1. Each row [a,b] in friendships means that a and b are direct friends.
Build referral recommendations for user:
Exclude user and every current direct friend.
A remaining user is eligible only when they share at least one mutual friend with user.
If d is the number of direct friends of user, a candidate with m distinct mutual friends has score m / d. Thus every score is in [0,1].
Rank candidates by decreasing score, breaking ties by increasing user ID, and keep the first k.
Return each kept recommendation as "userId:score", with the score rounded to exactly six digits after the decimal point. Return an empty array when no candidate is eligible.
Evaluation follow-up
NDCG can evaluate the ranking against graded relevance labels. Those labels are not part of this input, so NDCG does not change the judged return value.

Function
recommendReferrals(n: int, friendships: int[][], user: int, k: int) → String[]

Examples
Example 1
n = 6
friendships = [[0,1],[0,2],[1,3],[2,3],[1,4],[2,5]]
user = 0
k = 3
return = ["3:1.000000","4:0.500000","5:0.500000"]
User 3 shares both of user 0's friends and scores 2/2. Users 4 and 5 each score 1/2, so their IDs break the tie.
Example 2
n = 7
friendships = [[0,1],[0,2],[0,3],[1,4],[2,4],[3,5],[1,6],[2,6]]
user = 0
k = 2
return = ["4:0.666667","6:0.666667"]
Users 4 and 6 each share two of the target user's three friends. User 5 scores only 1/3, and the first two ranked candidates are returned.

Constraints
1 <= n <= 100000.
0 <= friendships.length <= 200000.
Every friendship contains two distinct valid user IDs, and no undirected edge is repeated.
0 <= user < n.
0 <= k <= n.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build an adjacency list. Mark user and all direct friends as excluded. For each direct friend f, walk f's neighbors. For every neighbor c not excluded, increment count[c]. Since edges are unique, each friend contributes at most once per candidate, so count[c] is the number of distinct mutual friends. Total work is bounded by the sum of friend degrees, fine for 200000 edges. Then sort candidates by count descending and ID ascending. Since d is the same for everyone, ranking by count is the same as ranking by score, which avoids float comparison bugs. Format with six decimals only at the end. Pitfalls: d equals 0 means no candidates, so return empty before dividing. Handle k = 0 and k larger than the candidate count. Ignore NDCG completely. If the clock is ugly and the sort-plus-format step trips you, StealthCoder is the hedge for the live OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Mutual-Friend Referral Recommendations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder
⏵ The honest play

You've seen the question. Make sure you actually pass Fireworks AI's OA.

Fireworks AI reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Mutual-Friend Referral Recommendations FAQ

What's the trick in Mutual-Friend Referral Recommendations?+

Count mutual friends by iterating over the target's direct friends and incrementing a counter for each non-excluded neighbor. No pairwise intersection needed. Then sort by count descending, ID ascending. Divide by d only when formatting the output string.

Do I need to worry about NDCG in this Fireworks AI question?+

No. The problem says the relevance labels aren't in the input, so NDCG doesn't affect the return value. It's context only. Skip it and spend your time on the counting, tie-break, and formatting logic.

How do I avoid floating-point tie-break errors?+

Sort on the integer mutual count, not the float score. Every candidate shares the same denominator d, so integer order matches score order exactly. Convert to m / d with six decimals only when building the output strings.

What edge cases break most solutions?+

The user has no friends, so d is 0 and you must return an empty array without dividing. Also k = 0, k greater than the candidate count, and forgetting to exclude the user and direct friends. Isolated nodes and candidates with zero mutual friends must not appear.

How should I prepare for this in 48 hours?+

Write it once from scratch: adjacency list, excluded set, counter map, sort with a two-key comparator, and string formatting to six decimals. Test both examples by hand. Practice the formatting call in your language so it doesn't surprise you under pressure.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Fireworks AI.

OA at Fireworks AI?
Invisible during screen share
Get it