24 · Heaps & Priority Queues

#355 Design Twitter

Mediumsolve on LeetCode ↗

frequently reported atAdobeSalesforcePayPalAmazonGoogleApple

the problem

In plain words

Implement postTweet(userId, tweetId), getNewsFeed(userId) — the 10 most recent tweet ids from the user and the people they follow, newest first — follow and unfollow.

in post(1,5); feed(1); follow(1,2); post(2,6); feed(1); unfollow(1,2); feed(1)

out [5], [6,5], [5]

  • 1 ≤ userId, followerId, followeeId ≤ 500
  • 0 ≤ tweetId ≤ 10⁴, all unique
  • At most 3·10⁴ calls in total

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

Design: implement every operation. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #23
    2. #146
      LRU Cache
      Mediumin Linked Lists