Design Twitter
Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and see the 10 most recent tweets in their news feed. Implement the Twitter class with postTweet, getNewsFeed, follow, and unfollow methods.

30:00

Design Twitter
medium
Topics
Companies

Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and see the 10 most recent tweets in their news feed. Implement the Twitter class with postTweet, getNewsFeed, follow, and unfollow methods.

Example 1:
Input: {"commands":["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"],"values":[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]}
Output: [null,null,[5],null,null,[6,5],null,[5]]
Constraints:
  • 1userId,followerId,followeeId5001 \leq \text{userId}, \text{followerId}, \text{followeeId} \leq 500

  • 0tweetId1040 \leq \text{tweetId} \leq 10^4

  • All tweets in the test cases have unique IDs.

  • At most 3×1043 \times 10^4 calls in total to postTweet, getNewsFeed, follow, and unfollow.

  • A user cannot follow themselves.

Input
arr ={"commands":["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"],"values":[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]}

Initialize Twitter

Operations

User Tweets

No tweets yet

Follows

No follows

News Feed (Top 10)

Empty feed

Current Op

Completed

Variables
No variables to display
DepthFunction Call
Stack empty
0/8