Logo
YouTubeDiscord
Constant Time
Constant Time
/Heaps
Heaps
/
#️⃣
Design twitter (K way merge in Reverse)
/
Notes to myself

Notes to myself

Things that I learned.

  1. Some feeds will not have any tweets but are still followed by the user. In those cases we check if there is a tweet before.
  2. # some feeds might be followed by the user but be empty
                if (len(tweetsByFollower)) > 0:
                    time,lastTweetIDByFollower = tweetsByFollower[len(tweetsByFollower)-1]
                    payLoad = (-1*time,lastTweetIDByFollower,tweetsByFollower,len(tweetsByFollower)-1)
                    heappush(heap,payLoad)
  3. There needs to be uniquness of userId’s in the follows lists. This is necessery to make sure we are not following one person twice and displaying their tweet ids in the feed twice
  4. def follow(self, followerId: int, followeeId: int) -> None:
            
            if not(followeeId in self.follows[followerId]) :
                self.follows[followerId].append(followeeId)
       
  5. with unfollow we need to be sure that before we unfollow that person exists. In the follows list trying to unfollow someone one that doesn’t will give us an error
  6. def unfollow(self, followerId: int, followeeId: int) -> None:
            print(self.follows[followerId],"before")
            if followeeId in self.follows[followerId]:
                self.follows[followerId].remove(followeeId)
  7. Tweet Id is not chronological. You need to create a seperate time stamp to achive that goal.