Reported September 2026
Visagraph

Top Mutual-Friend Recommendations

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

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

The Visa OA reported in September 2026 looks like a friend-recommendation toy, but one edge case sinks the naive version. You build an adjacency map, then count mutual friends for every non-friend of the target. Simple on paper. With up to 2 * 10^5 edges, the way you count decides whether you pass or time out. Candidates who loop over every pair of users get burned. This is a graph and hash map problem with a custom sort at the end. If you blank on the counting step during the live assessment, StealthCoder is the safety net running invisibly in the background.

The problem

You are given a list of friendships in a social network as an array friends. Each entry [u, v] represents a mutual friendship between users u and v. You are also given a target user t.
Suggest up to three new connections for t. Consider only users who:
are not the target user t; and
are not already direct friends of t.
For each candidate user p, count how many users are common friends of both p and t. Rank candidates by these rules:
A higher number of mutual friends comes first.
When counts tie, the lexicographically smaller user name comes first.
Return the first three user names in that order, or every candidate when fewer than three exist.

Function
recommendFriends(friends: String[][], t: String) → String[]

Examples
Example 1
friends = [["Alice","Bob"],["Alice","Carol"],["Alice","Dave"],["Bob","Carol"],["Bob","Eve"],["Bob","Frank"],["Carol","Dave"],["Carol","Grace"],["Dave","Grace"],["Dave","Henry"],["Eve","Frank"],["Eve","Grace"],["Frank","Grace"]]
t = "Alice"
return = ["Grace","Eve","Frank"]
Alice's direct friends are Bob, Carol, and Dave. The eligible candidates are Eve, Frank, Grace, and Henry. Grace shares two friends with Alice. The other three each share one, so lexical order selects Eve and Frank for the remaining positions.
Example 2
friends = [["A","B"],["B","C"],["B","D"]]
t = "A"
return = ["C","D"]
C and D each share B with A, so both are returned in lexical order.

Constraints
2 <= friends.length <= 2 * 10^5.
Every friends[i] contains exactly two user names and represents one undirected friendship.
Every user name has length at most 10 and contains only Latin letters.
The graph has no self-loops or duplicate undirected edges.
The target user t appears in at least one friendship pair.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: don't compare t against every other user. Walk t's direct friends instead. For each friend f, walk f's neighbors. Each neighbor p that isn't t and isn't already a direct friend of t gets one point in a hash map. That count is exactly the number of mutual friends, and total work is bounded by the edges touching t's friends. The pitfall is the exclusion set. Forget to drop t itself or t's direct friends and you recommend people who are already connected. Another trap is candidates with zero mutual friends. By the rules, a user who never appears via a friend of t is not scored, so the fewer-than-three case matters. Sort by count descending, then name ascending, and take three. Use plain string comparison for lexical order. If the sort comparator or the exclusion logic slips under pressure, StealthCoder can hand you the clean version during the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Top Mutual-Friend 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Visa reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Top Mutual-Friend Recommendations FAQ

What's the core trick in the Visa mutual-friend problem?+

Count from the target outward. For each direct friend of t, loop through that friend's neighbors and increment a counter for each valid candidate. This avoids comparing t against every user and keeps the work tied to the edges near t, which fits the 2 * 10^5 edge limit.

Which edge cases break a naive solution here?+

Recommending t itself, recommending users who are already direct friends of t, and mishandling ties. Also watch for fewer than three candidates, where you return all of them. In Example 2, only C and D qualify, so the result has length two.

How should I sort the candidates?+

Sort by mutual count descending, then by name ascending using normal string comparison. Names are Latin letters only, so default lexicographic order works. Then slice the first three. Don't use a heap unless you want to, since a full sort is fine at this scale.

Is this graph or hash table pattern still asked in OAs?+

Yes. Adjacency map plus counting plus custom sort shows up constantly in social network style questions. Visa reported this one in September 2026. The pattern is the same as friend-of-friend recommendation, so knowing it once covers many variants.

How do I prepare for this in 48 hours?+

Write the solution from scratch twice. Build the adjacency map with sets, count mutual friends via t's neighbors, exclude t and its friends, then sort with a two-key comparator. Test on both examples and one case with fewer than three candidates. That covers nearly everything the problem can throw.

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

OA at Visa?
Invisible during screen share
Get it