Design Twitter
Medium · Heap & Priority Queue · about 25 minutes
Asked at Amazon, X (Twitter), Microsoft, Google, Meta.
Design a simplified Twitter.
Twitter()creates the service.postTweet(userId, tweetId)posts a new tweet with a uniquetweetId(tweets are timestamped in call order).getNewsFeed(userId)returns the ids of the 10 most recent tweets posted by the user or by anyone they
follow, most recent first.
follow(followerId, followeeId)/unfollow(followerId, followeeId)change who a user follows. Following
yourself has no effect on the feed beyond your own tweets, which are always included.