Design a simplified version of Twitter where users can post tweets, follow/unfollow other users, and see the 10 most recent tweets in their news feed.
Implement the Twitter class:
Twitter() - initializes the Twitter object.postTweet(userId, tweetId) - composes a new tweet with ID tweetId by user userId. Each call to this function will use a unique tweetId.getNewsFeed(userId) - retrieves the 10 most recent tweet IDs in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user themselves. Tweets must be ordered from most recent to least recent.follow(followerId, followeeId) - the user with ID followerId starts following the user with ID followeeId.unfollow(followerId, followeeId) - the user with ID followerId stops following the user with ID followeeId.Input: ["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"]
[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]
Output: [null,null,[5],null,null,[6,5],null,[5]]
Explanation: User 1 posts tweet 5. User 1's feed shows [5]. User 1 follows user 2.
User 2 posts tweet 6. User 1's feed shows [6,5]. User 1 unfollows user 2.
User 1's feed shows [5] again.
Input: follow(1,2), postTweet(1,1), postTweet(2,2), postTweet(1,3), getNewsFeed(1)
Output: [3,1,2] -- wait, let's trace it:
User 1 follows user 2 first, then tweets id=1, user 2 tweets id=2,
user 1 tweets id=3. Feed: tweet 3 (most recent from user 1),
tweet 2 (from followed user 2), tweet 1 (older from user 1).
Input: operations = [follow(1,2), postTweet(1,1), postTweet(2,2), postTweet(1,3), getNewsFeed(1)] Output: [3, 2, 1] Explanation: The 3 most recent tweets across user 1 and user 2 are returned in reverse-chronological order.
1 <= userId, followerId, followeeId <= 5000 <= tweetId <= 10^43 * 10^4 calls will be made to all functions combined.LeetCode example: post, follow, post, feed, unfollow, feed