FastPrepVersioned Followers and Followees
Problems/Versioned Followers and Followees

Versioned Followers and Followees

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OpenAI phone screen for a full-time role. The report names the follow-up of getting followers and followees. It leaves out when the snapshot is taken, the order of the lists, the constraints, and how it is run. We filled those in.

Our version is about 70% the same as the reported question.

A directed social graph has n users numbered from 0 to n - 1. A relationship u -> v means that user u follows user v.

Process a finite sequence of relationship updates, immutable snapshots, and historical list queries. Every snapshot includes all earlier updates. Later updates never change an earlier snapshot.

Operations

  • FOLLOW u v activates u -> v. The relationship is inactive immediately before the command.
  • UNFOLLOW u v deactivates u -> v. The relationship is active immediately before the command.
  • SNAPSHOT creates the next snapshot. IDs start at 0. Append the ID as a decimal string.
  • GET_FOLLOWERS user snapshot_id appends all users who followed user at that snapshot.
  • GET_FOLLOWEES user snapshot_id appends all users whom user followed at that snapshot.

Serialize each relationship list as a string containing ascending user IDs inside brackets, separated by commas and no spaces. Serialize an empty list as []. Only SNAPSHOT, GET_FOLLOWERS, and GET_FOLLOWEES produce output. Return those strings in command order.

Historical Storage

For this exercise, assume each directed relationship is stored as a change history and the whole graph is not copied for each snapshot. Use that history model to answer snapshot queries.

Function

getVersionedRelationships(n: int, operations: String[]) → String[]

Examples

Example 1

n = 4operations = ["FOLLOW 0 1","FOLLOW 2 1","SNAPSHOT","GET_FOLLOWERS 1 0","GET_FOLLOWEES 0 0"]return = ["0","[0,2]","[1]"]

At snapshot 0, users 0 and 2 follow user 1. User 0 follows only user 1.

Example 2

n = 3operations = ["SNAPSHOT","GET_FOLLOWERS 1 0","FOLLOW 0 1","FOLLOW 0 2","SNAPSHOT","GET_FOLLOWEES 0 0","GET_FOLLOWEES 0 1"]return = ["0","[]","1","[]","[1,2]"]

Snapshot 0 is empty. The two later follows appear in snapshot 1 without changing snapshot 0.

Example 3

n = 5operations = ["FOLLOW 0 2","SNAPSHOT","FOLLOW 1 2","UNFOLLOW 0 2","FOLLOW 0 3","SNAPSHOT","GET_FOLLOWERS 2 0","GET_FOLLOWERS 2 1","GET_FOLLOWEES 0 1"]return = ["0","1","[0]","[1]","[3]"]

User 0 follows 2 in snapshot 0. Before snapshot 1, user 1 follows 2, while user 0 replaces that relationship with 0 -> 3.

Constraints

  • 1 <= n <= 2000
  • 1 <= operations.length <= 20000
  • 0 <= u, v, user < n and u != v
  • Every FOLLOW targets an inactive relationship.
  • Every UNFOLLOW targets an active relationship.
  • Every list query references a snapshot that has already been created.
  • Commands contain single spaces between tokens.
  • At least one command produces output.

More OpenAI Phone Screen questions

  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
  • Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
  • Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Consistent-Hash Packet RouterAmazon · PHONE SCREEN
  • Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions
  • Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
  • Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
  • Time-Based Key-Value StoreCockroach Labs · PHONE SCREEN · ONSITE INTERVIEW
  • Time Map with Sum and AverageConfluent · PHONE SCREENConfluent interview questions
  • Time-Based Key-Value StoreVerkada · PHONE SCREENVerkada interview questions

OpenAI interview experiences

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] getVersionedRelationships(int n, String[] operations) {
      // write your code here
    }

}
Checking account…