PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Software Engineering Fundamentals/OpenAI

Design a social network with snapshots

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of data structures, graph representations, immutability and snapshot/versioning strategies for in-memory systems, along with algorithmic reasoning for query and recommendation operations.

  • medium
  • OpenAI
  • Software Engineering Fundamentals
  • Software Engineer

Design a social network with snapshots

Company: OpenAI

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

You are asked to design and implement an in-memory **SocialNetwork** class that supports users following each other and creating **snapshots** of the follow graph. ### Requirements Implement an API similar to: ```text social_network = SocialNetwork() social_network.add_user("A") social_network.add_user("B") social_network.follow("A", "B") snapshot = social_network.create_snapshot() assert snapshot.is_follow("A", "B") ``` A **snapshot** represents an immutable view of the follow relationships at the moment it was created. ### Part 1 — Snapshot follow query - Support `snapshot.is_follow(u, v)` which returns whether user `u` follows user `v` **in that snapshot**. ### Part 2 — List followers and followees For a given snapshot and user: - Return the list/set of **followers** (who follows this user). - Return the list/set of **followees** (whom this user follows). ### Part 3 — Recommend users to follow Given a snapshot, a user `u`, and an integer `k`, recommend up to `k` users for `u` to follow using this logic: 1. Look at the users that `u` already follows. 2. For each of those followees, look at whom they follow. 3. Count how many times each candidate user is followed by `u`’s followees. 4. Return the top-`k` candidates by this count. ### Assumptions / clarifications (you may choose reasonable defaults) - What to do if `u` or `v` does not exist. - Whether to allow self-follow. - Whether repeated `follow` calls are idempotent. - Whether to exclude users that `u` already follows from recommendations. Describe your design (data structures, snapshot strategy, complexity) and any edge cases.

Quick Answer: This question evaluates understanding of data structures, graph representations, immutability and snapshot/versioning strategies for in-memory systems, along with algorithmic reasoning for query and recommendation operations.

Related Interview Questions

  • Implement an Extensible Chatbot App - OpenAI (medium)
  • Build a Reliable Streaming Chat UI - OpenAI (hard)
  • Design an Extensible Simulation Engine - OpenAI (hard)
  • Model particle hits on a screen - OpenAI (hard)
  • Analyze matrix multiplication complexity - OpenAI (hard)
OpenAI logo
OpenAI
Nov 16, 2025, 12:00 AM
Software Engineer
Technical Screen
Software Engineering Fundamentals
25
0
Loading...

You are asked to design and implement an in-memory SocialNetwork class that supports users following each other and creating snapshots of the follow graph.

Requirements

Implement an API similar to:

social_network = SocialNetwork()
social_network.add_user("A")
social_network.add_user("B")
social_network.follow("A", "B")

snapshot = social_network.create_snapshot()
assert snapshot.is_follow("A", "B")

A snapshot represents an immutable view of the follow relationships at the moment it was created.

Part 1 — Snapshot follow query

  • Support snapshot.is_follow(u, v) which returns whether user u follows user v in that snapshot .

Part 2 — List followers and followees

For a given snapshot and user:

  • Return the list/set of followers (who follows this user).
  • Return the list/set of followees (whom this user follows).

Part 3 — Recommend users to follow

Given a snapshot, a user u, and an integer k, recommend up to k users for u to follow using this logic:

  1. Look at the users that u already follows.
  2. For each of those followees, look at whom they follow.
  3. Count how many times each candidate user is followed by u ’s followees.
  4. Return the top- k candidates by this count.

Assumptions / clarifications (you may choose reasonable defaults)

  • What to do if u or v does not exist.
  • Whether to allow self-follow.
  • Whether repeated follow calls are idempotent.
  • Whether to exclude users that u already follows from recommendations.

Describe your design (data structures, snapshot strategy, complexity) and any edge cases.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.