LeetCode 355 ·
Medium
Design Twitter
Design a mini Twitter with postTweet, getNewsFeed (10 most recent), follow, unfollow.
Try it
Step through the core mechanic. The simulator below runs the heap shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Heap — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Store each user's tweets with a global timestamp. getNewsFeed merges the followees' recent tweets via a heap, taking the 10 newest — a k-way merge keyed by time.
| Aspect | Value |
|---|---|
| Pattern | Heap |
| Recognise it by | Merge recent posts across followees. |
| Time complexity | O(k log k) |
| Space complexity | O(n) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.