PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/OpenAI

Implement Social Follow Recommendations

Last updated: Jun 19, 2026

Quick Overview

This question evaluates graph data structure design and traversal, set-based aggregation and ranking logic, and the ability to justify data structure choices with time and space complexity analysis.

  • medium
  • OpenAI
  • Coding & Algorithms
  • Software Engineer

Implement Social Follow Recommendations

Company: OpenAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement an in-memory social network graph with three operations: - `follow(followerId, followeeId)`: record that one user follows another user. Duplicate follows should not create duplicate edges. Self-follow can be ignored or rejected, but state your choice. - `unfollow(followerId, followeeId)`: remove the follow edge if it exists. Removing a non-existent edge should be a no-op. - `recommend(userId, k)`: return up to `k` recommended users using a friend-of-friend rule. A candidate is any user followed by someone that `userId` follows. Exclude `userId` and users already followed by `userId`. Rank recommendations by the number of distinct intermediate users that connect `userId` to the candidate. Break ties deterministically, for example by smaller user id or lexicographic order. Discuss the data structures you would use and the time complexity of each operation.

Quick Answer: This question evaluates graph data structure design and traversal, set-based aggregation and ranking logic, and the ability to justify data structure choices with time and space complexity analysis.

Related Interview Questions

  • Consistent Hashing Ring with Virtual Nodes for Shard Rebalancing - OpenAI (hard)
  • Infection Spread Simulation with Death Threshold - OpenAI (medium)
  • Spreading Contagion on a Grid - OpenAI (medium)
  • Streaming Entropy with Numerical Stability - OpenAI (hard)
  • Implement a Distributed Rate Limiter - OpenAI (medium)
|Home/Coding & Algorithms/OpenAI

Implement Social Follow Recommendations

OpenAI logo
OpenAI
May 9, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
4
0
Practice Read
Loading...

Implement an in-memory social network graph with three operations:

  • follow(followerId, followeeId) : record that one user follows another user. Duplicate follows should not create duplicate edges. Self-follow can be ignored or rejected, but state your choice.
  • unfollow(followerId, followeeId) : remove the follow edge if it exists. Removing a non-existent edge should be a no-op.
  • recommend(userId, k) : return up to k recommended users using a friend-of-friend rule. A candidate is any user followed by someone that userId follows. Exclude userId and users already followed by userId .

Rank recommendations by the number of distinct intermediate users that connect userId to the candidate. Break ties deterministically, for example by smaller user id or lexicographic order. Discuss the data structures you would use and the time complexity of each operation.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,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
  • AI Coding 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.