FastPrepSocial Media Suggestions
Problems/Social Media Suggestions

Social Media Suggestions

Citadel logoCitadel● MediumINTERNNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Implement a prototype of a friend recommendation system for a social media application.

There are n users indexed from 1 to n, and m friends represented as a 2d array, friendships, where the ith friendship is a connection between users friendships[i][0] and friendships[i][1].

User x is suggested as a friend to user y if x and y are not friends and have the maximum number of common friends, i.e. a friend of both x and y. If there are multiple possible such users x, the one with the minimum index is suggested.

Given n and friendships, for each of the n users, find the index of the friend that should be recommended to them. If there is no recommendation available, report -1.

Function

getRecommendedFriends(n: int, friendships: int[][]) → int[]

Complete the function getRecommendedFriends in the editor.

getRecommendedFriends has the following parameters:

  1. int n: the number of users
  2. int friendships[m][2]: the friendships between the users

Returns int[]: an array of integers where the ith integer is the index of the recommended friend for the ith user, or -1 if no recommendation is available.

Key insight:

  • _handle edge cases_
  • No friends, no friends of friends (This is so true irl 🙂‍↕️)

૮₍ ˶•⤙•˶ ₎ა All thanks go to Aura Man!𓇼 𓆡⋆.˚

Examples

Example 1

n = 5friendships = [[0, 1], [0, 2], [1, 3], [2, 3], [3, 4]]return = [3, 2, 1, 0, 1]
Example 1 illustration

Example 2

n = 3friendships = [[0, 1], [1, 2], [2, 0]]return = [-1, -1, -1]
Example 2 illustration

Constraints

  • 1 ≤ n ≤ 10^5
  • 0 ≤ m ≤ 2.5 x 10^5
  • 0 ≤ friendships[i][0], friendships[i][1] < n
  • There are no self-loops or multiple edges.
  • Each user has a maximum of 15 friends.
  • The network of friends might be disconnected.

More Citadel interview questions

  • Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
  • Square Root FunctionPHONE SCREEN · Seen Oct 2026
  • Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
  • Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
  • Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
  • Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
  • Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
  • Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
  • Busy IntersectionOA · Seen Sep 2026
  • Shortest Path in an Unweighted GraphOA · Seen Sep 2026

Similar questions at other companies

  • Top Mutual-Friend RecommendationsVisa · OAVisa interview questions
  • Top Mutual-Friend RecommendationsSuperhuman · OASuperhuman interview questions
  • Find Minimum City HopsAmazon · OA
  • Fraud Ring SizeStripe · OAStripe interview questions
  • Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
  • Social Media Friend RecommendationGoogle · OAGoogle interview questions
  • Shared Interest 🌷Wolverine Trading · OAWolverine Trading interview questions
  • Race a Friend to a Shared HomeIntuit · OAIntuit interview questions
  • Shortest Route Through a Traced MazeDuolingo · OADuolingo interview questions
  • Do Two Nodes Share a Proper Ancestor?Compass International Holdings · OACompass International Holdings interview questions

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[] getRecommendedFriends(int n, int[][] friendships) {
      // write your code here
    }

}
Checking account…