Merge the Ten Most Recent Posts From Followed Accounts
Last updated: November 29, 2026
Quick Overview
Build a small social feed class supporting post, follow, unfollow and get_feed, where get_feed returns the 10 most recent post IDs from the user and everyone they follow.
0
0
0 solved
Build a small social feed class supporting post, follow, unfollow and get_feed, where get_feed returns the 10 most recent post IDs from the user and everyone they follow.
An object-oriented coding round in the style of Google onsites, loosely modeled on a Google Chat spaces or YouTube community feed. The interviewer checks a pull-model feed that merges per-user timelines with a heap instead of collecting and sorting everything.
What the Interviewer Expects
- Stores per-user post lists with a global timestamp
- Merges followed timelines with a k-way heap
- Stops after 10 results
- Handles self-follow and unfollowing someone not followed
- Discusses push versus pull trade-offs
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How does this change for a celebrity with millions of followers?
- Support pagination with a cursor
- Cache feeds and invalidate them on new posts
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
post(user, post_id): user publishes a post.follow(a, b)andunfollow(a, b).get_feed(user): up to 10 most recent post IDs from user and followees, newest first.- Ties are impossible be...
High-Level Design
Each user's posts are appended in time order, so each timeline is sorted by recency from its end. A feed is the top 10 of a k-way merge across the user's own timeline and each followee's.
Seed a max-...