Problem
Design a small version of Twitter. A tweet is a short message with a unique ID. A news feed is a list of recent tweets that a user sees.
Write the class Twitter with these operations:
Twitter() creates an empty system. postTweet(userId, tweetId) makes the user userId post a new tweet with the ID tweetId. follow(followerId, followeeId) makes the user followerId follow the user followeeId. unfollow(followerId, followeeId) makes the user followerId no longer follow the user followeeId. If followerId does not follow followeeId, unfollow does nothing.
getNewsFeed(userId) returns the IDs of the 10 most recent tweets in the news feed of userId. The news feed has the tweets of userId and the tweets of the users that userId follows. The list starts with the most recent tweet. If the feed has fewer than 10 tweets, return all of them.
Example 1
- Input:
- ["Twitter","postTweet","postTweet","getNewsFeed","follow","getNewsFeed","unfollow","getNewsFeed"] [[],[1,101],[2,201],[1],[1,2],[1],[1,2],[1]]
- Output:
- [null,null,null,[101],null,[201,101],null,[101]]
- Explanation:
- After
follow(1, 2), the feed of user 1 also has the tweet 201 of user 2. Afterunfollow(1, 2), the feed has only the tweet 101.
Example 2
- Input:
- ["Twitter","postTweet","follow","follow","postTweet","postTweet","getNewsFeed","getNewsFeed"] [[],[3,30],[4,3],[4,5],[5,50],[3,31],[4],[5]]
- Output:
- [null,null,null,null,null,null,[31,50,30],[50]]
- Explanation:
- User 4 follows users 3 and 5. The feed of user 4 shows their tweets from the newest to the oldest.
Constraints
- 1 <= userId, followerId, followeeId <= 500
- 0 <= tweetId <= 10^4
- All the tweets have unique IDs.
- followerId != followeeId
- At most 3 * 10^4 calls to postTweet, getNewsFeed, follow and unfollow
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- about your self coding questions framework questions
Coding
- An OOD style or implementation exstensive coding question. Logic is simple, no algorithm involved.
Coding
- Asked to complete a 3-part coding test in under 60 minutes. mostly basic stuff like data parsing, but a lot of small conditions make it difficult to complete in 60 minutes.
Coding
- Basic ones and then some basic coding
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 3 records
Coupang
Leetcode 355. Design Twitter
Reported Jun 20, 2026 · 2 source reports
STAFF
Source snapshot: Nov 12, 2026
View sourceGoogle
Design Twitter
Reported Jul 1, 2026 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceRead this source's wording
Design a social media platform similar to Twitter that allows users to follow/unfollow other users, post tweets, and view a personalized news feed of tweets from people they follow.
Headout
Design Twitter
Reported Jun 23, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
Read this source's wording
Design a social media platform similar to Twitter that allows users to follow/unfollow other users, post tweets, and view a personalized news feed of tweets from people they follow.