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:
Twitter() — Initializes the twitter object.postTweet(userId, tweetId) — Composes a new tweet with ID tweetId by the user userId. Each call to this function will be made with 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 themself. 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.["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"]\n[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]][null,null,[5],null,null,[6,5],null,[5]]1 <= userId, followerId, followeeId <= 5000 <= tweetId <= 10^4All the tweets have unique IDsAt most 3 * 10^4 calls will be made to postTweet, getNewsFeed, follow, and unfollowExpected time complexity: O(n log k)Run your code to see results
Use Cmd+Enter to run