Design Twitter
Hard Problems DSA practice problem on Onlearn.
Difficulty: medium.
Topics: How to design a system like Twitter, Design Twitter, Data Structures, Hash Map, Heap/Priority Queue, Object-Oriented Design, general programming, cache, data storage, System Design, Scalability & Performance, Architecture & Storage, Security.
Design a simplified version of Twitter where users can post tweets, follow other users, and view the most recent tweets in their news feed. The implementation should support the following operations: 1. postTweet(userId, tweetId): Composes a new tweet with tweetId by the user userId. 2. getNewsFeed(userId): Retrieves the 10 most recent tweet IDs in the user's news feed, ordered from most recent to least recent. The news feed should include tweets from the user and the users they follow. 3. follow(followerId, followeeId): Follower follows a followee. 4. unfollow(followerId, followeeId): Follower unfollows a followee. Note: Each tweet has a unique tweetId and a timestamp when it was posted. Constraints: 1 <= userId, tweetId, followerId, followeeId <= 1000 All IDs are unique. At most 1000 calls will be made to each function