Code RoomTwitter news feed
MediumPrep Room Coding #906

Twitter news feed

CodingAlgorithms & data structuresMid–Senior~35 min

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.

0:00 of about 35 min
InputExpectedGot
[[["postTweet",1,5],["getNewsFeed",1],["follow",1,2],["postTweet",2,6],["getNewsFeed",1],["unfollow",1,2],["getNewsFeed",1]]][[5],[6,5],[5]]not run yetsample