← Openai Interview Insights

Openai·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Got a system design question at OpenAI for a software engineer role, focused on data structure choices for a social graph lookup. Pretty focused interview, just the one problem but they really wanted to dig into the tradeoffs.

Questions Asked (1)

Q1

You're given a static snapshot of a social network's follow relationships. Design a method `follows(a, b)` that checks whether user A follows user B. What data structure would you use to store the snapshot, and what query complexity would you expect?

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

I went with a hash map of sets, one entry per user, each set holding the accounts they follow.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the requirements: the snapshot is static, so we can preprocess the follow relationships into a data structure optimized for membership queries. A hash set of (follower, followee) pairs gives O(1) average query time, but we should also discuss trade-offs with adjacency lists and memory considerations.

Pro tip: Mention that if the graph is dense, a bitset or Bloom filter could be more memory-efficient, but for sparse graphs a hash set is ideal. Also, note that the choice depends on whether we need to answer many queries or just a few.

1. Clarify requirements and constraints

Ask about the scale of the network (number of users, average follows per user), whether the snapshot is truly static, and if there are memory constraints. This shows you consider practical factors before choosing a data structure.

2. Propose a primary data structure

Suggest storing the follow relationships as a hash set of ordered pairs (A, B) or as an adjacency list (hash map from user to set of followees). Explain that this allows O(1) average-time membership checks.

3. Analyze query complexity and trade-offs

State that the query complexity is O(1) average for hash-based structures, but worst-case O(n) if many collisions. Compare with alternatives like sorted arrays (O(log n) with binary search) or bitsets (O(1) but high memory).

4. Discuss memory and preprocessing

Mention that preprocessing takes O(E) time to build the structure, where E is the number of edges. Memory is O(E) for hash set, which is efficient for sparse graphs. For dense graphs, consider bitsets or Bloom filters.

5. Summarize and recommend

Conclude that for a static snapshot with frequent membership queries, a hash set of pairs is a good default. If memory is tight and false positives are acceptable, a Bloom filter could be used, but it requires a fallback.

Key Points to Mention

  • Hash set of (follower, followee) pairs for O(1) average query time
  • Adjacency list representation (hash map from user to set of followees)
  • Trade-offs: memory vs. speed, worst-case vs. average complexity
  • Alternative structures: sorted array with binary search (O(log n)), bitset (O(1) but O(n^2) memory), Bloom filter (probabilistic)
  • Preprocessing time O(E) and memory O(E) for sparse graphs
  • Consideration of graph density and query frequency

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