← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Jul 2026

Summary

Meta SWE coding round built around a friend recommendation system, three sub-tasks that escalated from a straightforward bug fix to a graph-scoring problem with a complexity discussion at the end. The AI-assisted angle was a bit unusual but the underlying CS was pretty standard graph traversal stuff.

Questions Asked (3)

Q1

There's a bug in the valid_recommend function of a User class. Find and fix it.

Algorithms & Data Structures
Author's notes

The bug was pretty subtle if you didn't read the starter code carefully.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the expected behavior of valid_recommend and any edge cases, then systematically trace through the code to identify logical errors. After fixing the bug, explain your reasoning and test with representative inputs to ensure correctness.

Pro tip: Demonstrate a methodical debugging process by verbalizing your hypotheses and how you'd verify them, rather than jumping to a fix. This shows strong problem-solving skills and communication, which are highly valued at Meta.

1. Clarify Requirements

Ask questions to understand what valid_recommend is supposed to do, including input types, expected output, and edge cases.

2. Trace the Code

Walk through the function line by line with sample inputs to identify where the logic deviates from the expected behavior.

3. Identify the Bug

Pinpoint the exact line(s) causing the issue, considering common pitfalls like off-by-one errors, incorrect conditionals, or state mutation.

4. Propose and Implement Fix

Explain the fix clearly, implement it, and discuss any trade-offs or alternative solutions.

5. Test and Validate

Run through test cases, including edge cases, to confirm the fix works and doesn't introduce new bugs.

Key Points to Mention

  • Understanding the function's contract and expected behavior
  • Systematic debugging approach (e.g., print statements, unit tests)
  • Common bug patterns in recommendation logic (e.g., boundary conditions, data type mismatches)
  • Importance of testing edge cases (empty inputs, null values, large data)
  • Communication of thought process and reasoning
  • Consideration of time and space complexity in the fix

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Implement a random_recommend function that picks a random non-friend user for a given user.

Algorithms & Data StructuresAPI & Integrations
Author's notes

This is where the AI-assisted part came in.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: define what constitutes a non-friend user, discuss data structures for storing friendships, and consider scale. Then propose an efficient algorithm, such as using a hash set for friends and random sampling from the remaining users, and analyze trade-offs between precomputation and on-the-fly selection.

Pro tip: At Meta, scale is critical. Mention how you would handle billions of users by using techniques like reservoir sampling or precomputed recommendation pools, and discuss how to avoid bias in random selection.

1. Clarify requirements

Ask questions to understand constraints: Are we dealing with a static or dynamic friend list? What is the scale (number of users, average friends)? Should the recommendation be uniformly random or weighted? Are there any privacy or performance constraints?

2. Choose data structures

Decide how to represent the social graph. For a single user, a hash set of friend IDs allows O(1) lookup. For large-scale, consider adjacency lists or distributed storage. Discuss memory vs. speed trade-offs.

3. Design algorithm

Propose an algorithm: e.g., iterate through all users, skip friends, and use reservoir sampling to pick one uniformly at random in O(n) time and O(1) space. Alternatively, if the set of non-friends is large, precompute or use indexing to sample efficiently.

4. Analyze complexity and optimize

Analyze time and space complexity. For O(n) scan, discuss if it's acceptable. For better performance, suggest precomputing a list of non-friends per user (if memory allows) or using a randomized approach with rejection sampling, considering the density of friends.

5. Handle edge cases and scale

Address edge cases: user has no non-friends, user has many friends, or the graph is huge. Discuss distributed solutions like MapReduce or using a graph database, and how to ensure randomness without bias.

Key Points to Mention

  • Uniform random selection: ensure each non-friend has equal probability.
  • Reservoir sampling: efficient O(n) time, O(1) space for random selection from a stream.
  • Hash set for friend lookup: O(1) average time to check if a user is a friend.
  • Trade-offs: precomputation vs. on-the-fly, memory vs. latency.
  • Scalability: handling billions of users with distributed systems or approximation.
  • Edge cases: no non-friends, user with all friends, empty friend list.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Implement a Top-K friend recommendation function that ranks candidates by number of mutual friends. Then walk through the time complexity and discuss how the scoring metric would change for second-degree connections.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

Scoring by intersection size is simple enough but the discussion afterward is where they actually cared.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: define the graph representation, what 'mutual friends' means, and constraints like Top-K size. Then outline an algorithm: for each candidate, compute mutual friends by intersecting adjacency lists, and use a min-heap to maintain the top K. Finally, analyze time complexity and discuss how the scoring changes for second-degree connections.

Pro tip: Mention that for large-scale systems, you'd precompute or approximate mutual friends using techniques like MinHash or locality-sensitive hashing, and that the scoring metric for second-degree connections might weight mutual friends by their own connection strength or use path counts.

1. Clarify requirements and assumptions

Ask about the graph size, whether it's directed or undirected, if friend lists are sorted, and if we need exact Top-K or approximate results. Confirm that mutual friends count is the primary score.

2. Design the algorithm

For each candidate (friends-of-friends), compute mutual friends by intersecting the user's friend set with the candidate's friend set. Use a hash set for O(1) lookups, and maintain a min-heap of size K to track top candidates.

3. Analyze time and space complexity

Time: O(F * C) where F is average friend count and C is number of candidates, but with hash sets it's O(sum of degrees of candidates). Space: O(F + K) for sets and heap. Discuss optimizations like early termination or pruning.

4. Discuss second-degree connections

Explain that second-degree connections are friends-of-friends-of-friends. Scoring could be based on number of mutual friends at second degree, or weighted by the strength of the intermediate connection (e.g., number of mutual friends with the intermediary).

5. Consider scalability and trade-offs

For large graphs, exact computation is expensive. Mention approximate algorithms (e.g., sampling, MinHash) and precomputation. Discuss trade-offs between accuracy and latency.

Key Points to Mention

  • Graph representation: adjacency lists or hash sets for O(1) friend lookups.
  • Mutual friends computation: intersection of friend sets, using hash sets for efficiency.
  • Top-K selection: min-heap of size K to avoid sorting all candidates.
  • Time complexity: O(N * d) where N is number of candidates and d is average degree, or O(E) if iterating edges.
  • Second-degree scoring: could be sum of mutual friends of intermediaries, or weighted by connection strength.
  • Scalability: precomputation, approximation algorithms (MinHash, LSH), and distributed processing.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.