Code Room
CodingMediumcod-g336
Subject Design data structuresLevel Mid–Senior~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Design a mini Twitter and process a list of operations: ['postTweet', userId, tweetId], ['follow', followerId, followeeId], ['unfollow', followerId, followeeId], and ['getNewsFeed', userId]. getNewsFeed returns the 10 most recent tweet ids (newest first) posted by the user or anyone they follow. A user always implicitly follows themselves; following yourself explicitly is a no-op. Return the list of feeds produced by each getNewsFeed op.

Implement
twitter_feed(ops: list[list]) → list[list[int]]
Examples
in[[["postTweet",1,5],["getNewsFeed",1],["follow",1,2],["postTweet",2,6],["getNewsFeed",1],["unfollow",1,2],["getNewsFeed",1]]]out[[5],[6,5],[5]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.