cheetcode

69. Design TwitterMedium

Design a miniature social feed with posting, following, unfollowing, and recent-feed lookup.

Design a small Twitter-like service with posting, following, unfollowing, and news-feed lookup. A user's feed should include their own tweets and tweets from followed users.

Return the 10 most recent tweet ids for the feed, ordered from newest to oldest.

Design a simplified version of Twitter where users can post tweets, follow and unfollow each other, and retrieve the 10 most recent tweet ids in their news feed.

Use a heap when the next smallest or largest candidate matters more than the full sorted order. Keep stale or no-longer-valid entries from affecting the answer.

Examples

Input: operations = ["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"], args = [[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]
Output: [null,null,[5],null,null,[6,5],null,[5]]
Input: operations = ["Twitter","postTweet","postTweet","getNewsFeed"], args = [[],[1,7],[1,8],[1]]
Output: [null,null,null,[8,7]]

Constraints

  • 1 <= operations.length <= 10,000
  • 1 <= userId, followerId, followeeId, tweetId <= 500