Problem
Build a tiny social feed as a class Twitter:
- post_tweet(user_id, tweet_id) (postTweet): the user posts a tweet with a unique id.
- get_news_feed(user_id) (getNewsFeed): return the ids of the 10 most recent tweets posted by the user or anyone they follow, newest first.
- follow(follower_id, followee_id): the follower starts following the followee.
- unfollow(follower_id, followee_id): the follower stops following them.
Users always see their own tweets. Following yourself, unfollowing someone you do not follow, and following someone twice should all be harmless.
Example 1
t = Twitter()
Example 2
t.post_tweet(1, 5)
Example 3
- Input
- t.get_news_feed(1)
- Output
- [5]
Example 4
t.follow(1, 2)
Example 5
t.post_tweet(2, 6)
Example 6
- Input
- t.get_news_feed(1)
- Output
- [6, 5]
Example 7
t.unfollow(1, 2)
Example 8
- Input
- t.get_news_feed(1)
- Output
- [5]
Constraints
1 <= user_id, follower_id, followee_id <= 5000 <= tweet_id <= 10^4, and every tweet id is unique.At most 3 * 10^4 calls are made in total.