Reported July 2024
Citadelgraph

Get Recommended Friends

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

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

Citadel hit candidates with this in July 2024, and it's a graph problem disguised as a social network query. You're given user relationships and need to return friend recommendations, likely based on mutual connections or some ranking heuristic. The trick is figuring out what 'recommended' actually means in their scoring system. This is the kind of problem where the vague spec is half the challenge. StealthCoder will help you nail the implementation once you've decoded the rules.

Pattern and pitfall

The core pattern is graph traversal combined with counting or ranking. You'll build an adjacency list from the input relationships, then either do a breadth-first search or depth-first search to find second-degree connections (friends of friends). The catch is the sorting: candidates usually miss whether you're ranking by mutual friend count, by some weighting scheme, or by input order. Common pitfall is returning already-connected nodes or not filtering properly. The implementation is straightforward once you lock down the scoring logic. StealthCoder acts as your safety net if you blank on the traversal order or the exact output format during the live assessment.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Get Recommended Friends 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as number of islands. If you have time before the OA, drill that.

⏵ The honest play

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

Citadel reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Get Recommended Friends FAQ

What does 'recommended' mean for this problem?+

Almost certainly means friends-of-friends (second-degree connections) that aren't already your direct friends. The recommendation score is likely the count of mutual friends between you and the candidate. Check the examples carefully for the ranking order.

Do I need to return all recommendations or just the top N?+

The problem statement will specify. If it doesn't, assume all non-connected second-degree nodes, sorted by mutual friend count descending. Look at the output constraints in the examples.

Should I use BFS or DFS?+

Either works for finding reachable nodes, but BFS is cleaner for 'friends at distance 2'. DFS will also work if you track depth. Just be consistent and handle visited nodes correctly to avoid cycles.

How do I handle ties in recommendation ranking?+

If two users have the same mutual friend count, the problem will hint at a tiebreaker: usually user ID order, input order, or alphabetical. Read the examples carefully or assume ID ascending order if not specified.

What's the time complexity they're expecting?+

O(V plus E) for graph traversal, where V is users and E is friendships. Sorting recommendations adds O(K log K) where K is the count of candidates. That's acceptable. Don't overthink optimization unless it times out.

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

OA at Citadel?
Invisible during screen share
Get it