DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Heap

Design Twitter

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Design Twitter** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Hash map + min-heap merge recent k tweets **Edge Cases to Consider:** - (1) Unfollow own account - (2) No tweets yet - (3) User follows many with sparse tweets

Examples

Example 1
Input: postTweet(1,5); getNewsFeed(1)
Output: [5]
Explanation: Own tweet
Example 2
Input: postTweet(1,5); follow(1,2); postTweet(2,6); getNewsFeed(1)
Output: [6,5]
Explanation: Follow then get feed
Example 3
Input: postTweet(1,5); getNewsFeed(2)
Output: []
Explanation: User 2 sees nothing

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪Unfollow own account
  • ▪No tweets yet
  • ▪User follows many with sparse tweets
Frequently Asked At
AmazonMicrosoftMetaUber