PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Build Friend Recommendations

Last updated: Apr 16, 2026

Quick Overview

This question evaluates proficiency with graph data structures, set operations, uniform random sampling, counting mutual connections, and deterministic tie-breaking in recommendation logic.

  • medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Build Friend Recommendations

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a social graph and a `User` class that stores a user id and the set of direct friends for each user. Complete a recommendation module with the following parts: 1. Fix `valid_recommend(user, candidate)` so it returns `false` when the candidate is the same as the user or is already a direct friend, and `true` only for valid unseen candidates. 2. Implement `random_recommend(user, k)` to return up to `k` valid recommended users chosen uniformly at random from all valid candidates. 3. Implement `top_k_mutual_friend_recommend(user, k)` that ranks valid candidates by the number of mutual friends with the target user, breaks ties deterministically, and returns the top `k`. Explain the time complexity of your recommendation approach and the data structures you use.

Quick Answer: This question evaluates proficiency with graph data structures, set operations, uniform random sampling, counting mutual connections, and deterministic tie-breaking in recommendation logic.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Feb 8, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
1
0
Loading...

You are given a social graph and a User class that stores a user id and the set of direct friends for each user. Complete a recommendation module with the following parts:

  1. Fix valid_recommend(user, candidate) so it returns false when the candidate is the same as the user or is already a direct friend, and true only for valid unseen candidates.
  2. Implement random_recommend(user, k) to return up to k valid recommended users chosen uniformly at random from all valid candidates.
  3. Implement top_k_mutual_friend_recommend(user, k) that ranks valid candidates by the number of mutual friends with the target user, breaks ties deterministically, and returns the top k .

Explain the time complexity of your recommendation approach and the data structures you use.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.