LC 355
LeetCode 355 · Medium

Design Twitter

Design a mini Twitter with postTweet, getNewsFeed (10 most recent), follow, unfollow.

Heap → · Medium frequency · Solve on LeetCode →

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.

AspectValue
PatternHeap
Recognise it byMerge recent posts across followees.
Time complexityO(k log k)
Space complexityO(n)
DifficultyMedium

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.