← Meta

Meta AI-assisted CodingAI-CodingFree previewFree

Friend Recommendation

Last asked

MedonsiteSWEMLE
SWEMLEai-codinggraphoop-designmedium

Problem

Starter codebase exposes a User class with friends and valid_recommend helpers. Three sub-tasks build from logic-bug fix to AI-assisted random recommender to mutual-friends Top-K ranking.

Q1 — Logic-bug fix in valid_recommend

Typical bug: the function does not exclude the user themselves and/or existing friends from candidates.

Q2 — Implement random_recommend

Pick a random non-friend user. Prompt the AI with the class signature so the output matches the existing interface.

Q3 — Top-K mutual-friends recommendation

Score each candidate by |friends(u) ∩ friends(candidate)|; return the top K. Walk the interviewer through time complexity and discuss how the metric would change for second-degree connections.

Input scale and strategy choice

A September 2026 version supplies a list of users and user-user friendship pairs, with three test suites. The largest contains about 100,000 users and 1.5 million friendship pairs. Choose a strategy for recommending new friends; friends-of-friends and user popularity are suggested options.

Follow-ups

  • Evaluation follow-up: explain how to verify that the recommender works: build a held-out dataset and measure precision and recall.