Design Twitter
Design a simplified Twitter. Support postTweet(userId, tweetId) to publish a tweet; getNewsFeed(userId) to return the ids of the 10 most recent tweets in the user's feed, newest first, where the feed includes the user's own tweets and tweets from everyone they follow; follow(followerId, followeeId) and unfollow(followerId, followeeId) to manage the follow graph. A user does not follow themselves.
Open official problem prompt ↗Return each user's 10 newest tweets across themselves and everyone they follow, staying correct as follows change over time.
Like assembling a newspaper front page from several reporters' inboxes: each story is timestamped, and you print the 10 latest across all inboxes you subscribe to.
- Input
- postTweet(1,5); getNewsFeed(1); follow(1,2); postTweet(2,6); getNewsFeed(1); unfollow(1,2); getNewsFeed(1)
- Output
- [5]; [6, 5]; [5]
- Why
- After following user 2, user 1's feed merges tweet 6 (newer) then 5; after unfollowing, only user 1's own tweet 5 remains.
1 <= userId, tweetId, followerId, followeeId <= 500tweetId values are unique per postTweet callAt most 3 * 10^4 total calls across all methodsA feed returns at most 10 tweets