← Openai Interview Insights

Openai·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026Remote

Summary

OpenAI SWE interview with a graph-based recommendation problem. The core of it was designing a 'people you may know' feature on top of a follow graph, which sounds approachable until you get into the edge cases and complexity analysis.

Questions Asked (1)

Q1

Given a social graph that supports follow and unfollow operations, implement a function to recommend the top K users for a given user U to follow, ranked by how many of U's existing followees also follow each candidate. Discuss edge cases and the complexity of your approach.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I got the basic loop right pretty quickly: iterate over U's followees, then over each of their followers, accumulate counts in a hashmap, then use a min-heap to pull out top K.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the graph representation and constraints, then propose a two-phase algorithm: first gather all followees of U, then for each followee, iterate over their followees and count occurrences, excluding U and already-followed users. Finally, select the top K candidates using a min-heap or sorting, and analyze time and space complexity.

Pro tip: Mention that in a real system, this recommendation is often precomputed offline or approximated with MapReduce/streaming due to scale, and discuss trade-offs between exactness and latency.

1. Clarify requirements and assumptions

Ask about graph size, whether the graph is directed (follow is directed), if U can be recommended to themselves, and if candidates already followed by U should be excluded.

2. Choose data structures and algorithm

Represent the graph as an adjacency list for followees. Use a hash map to count how many of U's followees follow each candidate, iterating over each followee's followees.

3. Handle edge cases and exclusions

Exclude U and users already followed by U from recommendations. Handle cases where U has no followees, no candidates, or K is larger than the number of candidates.

4. Select top K efficiently

Use a min-heap of size K to track top candidates in O(N log K) time, or sort all candidates in O(N log N) if K is large. Discuss trade-offs.

5. Analyze complexity and discuss scalability

Time complexity: O(F * A + N log K) where F is number of followees, A is average followees per followee, N is number of candidates. Space: O(N). Mention distributed approaches for large graphs.

Key Points to Mention

  • Directed graph representation and adjacency list
  • Counting mutual followees using a hash map
  • Excluding U and already-followed users
  • Using a min-heap for top K selection
  • Time and space complexity analysis
  • Scalability considerations for large social graphs

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