Mini Twitter
Design a mini-Twitter. Operations in order: ['post', user, tweetId] (a global timestamp increments per post), ['follow', a, b] (a follows b), ['unfollow', a, b], and ['feed', user] which returns the 10 most recent tweet ids from the user and everyone they follow, newest first. A user always implicitly follows themselves. Return the list of feeds (each a list of tweet ids) for each 'feed' op.
Implement
design_twitter(ops: list[list]) → list[list[int]]Examples
in
[[["post",1,101],["feed",1],["follow",1,2],["post",2,201],["feed",1],["unfollow",1,2],["feed",1]]]out[[101],[201,101],[101]]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
solution.py
InputExpectedGot
[[["post",1,101],["feed",1],["follow",1,2],["post",2,201],["feed",1],["unfollow",1,2],["feed",1]]][[101],[201,101],[101]]not run yetsample