bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 355. Design Twitter

355. Design Twitter

Leetcode Solutions

Using HashMap and PriorityQueue

  1. Initialize a HashMap to store user's tweets and another to store the users they follow.
  2. For postTweet, add the tweet with a timestamp to the user's tweet list in the HashMap.
  3. For getNewsFeed, use a PriorityQueue to fetch the 10 most recent tweets from the user and the users they follow.
  4. For follow, add the followee to the follower's set in the followings HashMap.
  5. For unfollow, remove the followee from the follower's set in the followings HashMap.
UML Thumbnail

Using HashMaps and Lists

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...