355. Design Twitter
Practice Design Twitter for free on NudgeCode: Medium, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a small social feed.
postTweet(userId, tweetId)posts a new tweet with a unique id.getNewsFeed(userId)returns the ids of the 10 most recent tweets posted by the user or anyone they follow, newest first (fewer than 10 if there are not that many).follow(followerId, followeeId)/unfollow(followerId, followeeId)start or stop following. Following yourself or unfollowing someone you do not follow has no effect.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for the constructor and for calls that return nothing).
Example
["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"]
[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]
-> [null,null,[5],null,null,[6,5],null,[5]]
Constraints
- 1 <= userId, followerId, followeeId <= 500
- 0 <= tweetId <= 10^4, and every tweet id is unique
- Up to 3 * 10^4 calls in total