Design a simplified version of Twitter where users can post tweets, follow and unfollow other users, and retrieve the 10 most recent tweet IDs in their news feed — a mix of their own tweets and those from users they follow, most recent first.
postTweet(1,5); getNewsFeed(1)[5]follow(1,2); postTweet(2,6); getNewsFeed(1)[6,5]Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A heap keeps the minimum (or maximum) element accessible in O(1), with O(log n) insert and remove. It's the tool whenever you repeatedly need "the smallest/largest remaining item" without needing everything fully sorted.
Read the full Heap / Priority Queue guide →
Original problem on LeetCode ↗