← Openai Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Coding round at OpenAI for a software engineer role, focused entirely on a social graph problem that kept building in complexity across four parts. Got through most of it but ran out of steam on the last one.

Questions Asked (4)

Q1

Design a FriendCircle class that supports follow, unfollow, and snapshot operations.

System DesignAlgorithms & Data Structures
Author's notes

Seemed straightforward at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the requirements and constraints first, then design the data structures and algorithms for follow, unfollow, and snapshot operations. Discuss trade-offs between different approaches, focusing on time and space complexity, and consider scalability for large user bases.

Pro tip: Demonstrate awareness of real-world constraints by discussing how to handle massive scale, such as sharding or caching, and mention that snapshot could be implemented with copy-on-write or versioning to avoid expensive full copies.

1. Clarify Requirements

Ask questions to understand expected scale (number of users, follows), snapshot semantics (point-in-time view, consistency), and performance requirements (latency, throughput).

2. Design Data Structures

Choose appropriate data structures for storing user relationships, such as adjacency lists (hash maps) for follows, and consider how to efficiently capture snapshots.

3. Implement Operations

Define algorithms for follow, unfollow, and snapshot. For snapshot, consider approaches like deep copy, persistent data structures, or versioned logs.

4. Analyze Trade-offs

Compare time and space complexity of different designs. Discuss trade-offs between snapshot cost and query performance, and between memory usage and speed.

5. Optimize and Scale

Propose optimizations for large-scale systems, such as sharding, caching, or using distributed databases, and discuss how to handle concurrent operations.

Key Points to Mention

  • Choice of data structures (e.g., hash maps, sets, graphs) and their impact on operation complexity.
  • Snapshot implementation strategies: deep copy, copy-on-write, persistent data structures, or versioning.
  • Time and space complexity analysis for each operation.
  • Scalability considerations: sharding, caching, distributed storage, and eventual consistency.
  • Concurrency and consistency: handling simultaneous follows/unfollows and snapshot isolation.
  • Real-world examples or analogies (e.g., social networks like Twitter/Facebook) to ground the design.

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

Q2

Given a snapshot of the social graph, return all friends of a given user.

Algorithms & Data Structures
Author's notes

Pretty clean traversal question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the graph representation (adjacency list vs. adjacency matrix) and whether the graph is directed or undirected. Then, choose the appropriate traversal or lookup method: if the graph is stored as an adjacency list, simply return the list for the given user; if as a matrix, scan the row for the user. Discuss time and space complexity, and consider edge cases like user not found or no friends.

Pro tip: Mention that in a real-world system, you'd likely use a distributed graph database or cache for scalability, but for this problem, focus on the core algorithm and data structure choice. Also, proactively discuss handling large graphs and potential memory constraints.

1. Clarify the problem

Ask about the graph representation, directedness, and whether the user is guaranteed to exist. Confirm the expected output format (e.g., list of user IDs).

2. Choose data structure

Decide between adjacency list and adjacency matrix based on the given snapshot. Explain the trade-offs in terms of time and space.

3. Outline algorithm

If adjacency list: return the list for the user. If adjacency matrix: iterate through the user's row and collect indices where the value indicates friendship.

4. Analyze complexity

State the time complexity: O(1) for adjacency list (assuming direct access) or O(n) for adjacency matrix. Space complexity: O(degree) for output.

5. Handle edge cases

Discuss cases where the user has no friends, the user does not exist, or the graph is very large. Mention potential optimizations like caching.

Key Points to Mention

  • Graph representation: adjacency list vs. adjacency matrix
  • Directed vs. undirected graph and its impact on friendship symmetry
  • Time and space complexity of the chosen approach
  • Edge cases: user not found, no friends, self-loops
  • Scalability considerations for large social graphs
  • Potential use of hash maps for O(1) average lookup

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

Q3

Given a snapshot, implement a friend recommendation feature.

Algorithms & Data StructuresProduct Sense & Ideation
Author's notes

This is where it got more interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: define the snapshot (e.g., graph of users and friendships), the goal (recommend friends), and constraints (scale, latency). Then propose a baseline approach (e.g., friends-of-friends) and iterate with optimizations (e.g., ranking by mutual friends, handling large graphs). Finally, discuss evaluation metrics and potential improvements.

Pro tip: Demonstrate product sense by discussing how to rank recommendations (e.g., by mutual friends, interaction strength) and how to handle cold-start users. Also, mention scalability considerations like using MapReduce or graph processing frameworks.

1. Clarify requirements and assumptions

Ask questions to understand the snapshot format (e.g., adjacency list, edge list), scale (number of users, edges), and what 'friend recommendation' means (e.g., suggest new friends). Clarify constraints like latency, memory, and whether recommendations should be real-time or batch.

2. Propose a baseline algorithm

Suggest a simple approach: for each user, recommend friends-of-friends (2-hop neighbors) not already friends. Discuss how to compute this efficiently using BFS or by iterating over edges.

3. Optimize and rank recommendations

Improve the baseline by ranking candidates: e.g., sort by number of mutual friends, or use weighted edges (interaction frequency). Discuss pruning to avoid recommending popular users indiscriminately.

4. Address scalability and implementation

Explain how to handle large graphs: use distributed computing (e.g., MapReduce, Pregel) or approximate algorithms. Discuss data structures (e.g., hash maps for adjacency) and time/space complexity.

5. Evaluate and iterate

Propose evaluation metrics (e.g., precision@k, recall, click-through rate) and offline/online testing. Discuss potential improvements like incorporating user similarity or machine learning models.

Key Points to Mention

  • Graph representation and traversal (BFS/DFS) for finding friends-of-friends.
  • Ranking by mutual friends count or other signals (e.g., interaction strength).
  • Scalability: distributed processing (MapReduce, Pregel) and complexity analysis.
  • Handling edge cases: users with no friends, already friends, or private profiles.
  • Evaluation metrics: precision@k, recall, A/B testing.
  • Product considerations: cold-start, diversity of recommendations, and user privacy.

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

Q4

Compare two snapshots of the social graph and identify what changed in a user's friend list between them.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Ran out of time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the data model and constraints first, then propose an efficient algorithm using hash sets to compare the two snapshots in O(n+m) time. Discuss trade-offs between time and space, and handle edge cases like large graphs or streaming data.

Pro tip: Mention that you'd use a hash set for the smaller snapshot to minimize memory, and consider if the snapshots are sorted to enable a two-pointer approach with O(1) extra space. This shows awareness of practical constraints.

1. Clarify requirements and constraints

Ask about the size of the friend lists, whether the snapshots are sorted, memory limits, and if the result should include added, removed, or both. This ensures you design the right solution.

2. Choose data structures

Select hash sets for O(1) lookups if memory allows, or two-pointer technique if lists are sorted and memory is tight. Explain why the chosen structure fits the constraints.

3. Outline the algorithm

Describe step-by-step: build a set from one snapshot, iterate through the other to find differences, and collect added/removed friends. Analyze time and space complexity.

4. Handle edge cases

Discuss scenarios like empty lists, identical snapshots, very large lists that don't fit in memory, and duplicate entries. Propose solutions like streaming or external sorting.

5. Discuss trade-offs and optimizations

Compare approaches (e.g., hash set vs. sorting) in terms of time, space, and scalability. Mention potential optimizations like early termination or parallel processing.

Key Points to Mention

  • Time and space complexity analysis (O(n+m) time, O(min(n,m)) space with hash sets)
  • Use of hash sets for efficient membership testing
  • Two-pointer technique for sorted lists with O(1) extra space
  • Handling large datasets that don't fit in memory (streaming, external sorting)
  • Edge cases: empty lists, no changes, all friends added/removed
  • Trade-offs between different approaches and when to use each

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