Store each user’s tweets with timestamps. News feed is the 10 most recent tweets among the user and followees.
postTweet: append (time, tweetId) to user list.follow/unfollow: maintain followee set.getNewsFeed: k-way merge of the most recent tweet lists using a max-heap keyed by time.
Start with each user’s latest tweet, then push the previous tweet from that same user when popped.The heap always contains the next most recent candidate among all lists, producing the correct top-10 ordering.
Store each user’s tweets with timestamps. News feed is the 10 most recent tweets among the user and followees.
postTweet: append (time, tweetId) to user list.follow/unfollow: maintain followee set.getNewsFeed: k-way merge of the most recent tweet lists using a max-heap keyed by time.
Start with each user’s latest tweet, then push the previous tweet from that same user when popped.The heap always contains the next most recent candidate among all lists, producing the correct top-10 ordering.