Things that I learned.
- 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.
- 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
- 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
- Tweet Id is not chronological. You need to create a seperate time stamp to achive that goal.
# 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)
def follow(self, followerId: int, followeeId: int) -> None:
if not(followeeId in self.follows[followerId]) :
self.follows[followerId].append(followeeId)
def unfollow(self, followerId: int, followeeId: int) -> None:
print(self.follows[followerId],"before")
if followeeId in self.follows[followerId]:
self.follows[followerId].remove(followeeId)