it makes the overall time complexity still big o of k which is what we already originally had so it actually doesn't change the overall time complexity but the benefit is if you know if we were running this algorithm in a generic case where we didn't have to actually receive uh NUMBER_TOKEN different tweets maybe we had to receive up to n tweets our algorithm using a heap would be more efficient so i think i've talked enough about the complexity and how we're actually going to design this now it's actually time to implement the solution and code it up before we continue with the video let me just tell you a bit about algomonster as you prepare for your coding interviews on algo monster you'll actually get feedback on which categories you're strong in and which categories you could use a little more practice in you won't be wasting time solving random problems because algomonster has done some intelligent analysis on which categories of problems are asked more frequently and problems also come with solutions to make sure that you don't get stuck they've also got system design and object oriented design content and a bunch more a lot of the features you can actually check out for free but if you do want to subscribe you can get lifetime access and you can get NUMBER_TOKEN off with code neat okay so now let's code it up and just to save a bit of time i'm just going to copy and paste a few lines of code so remember we're going to have three main variables in our constructor we're going to keep track of the count initially it's going to be zero we're going to use the count to basically it would be better to call this time but really it's just counting our number of tweets so basically we can maintain which tweet was created earlier than another tweet we're also going gonna have a tweet map where we map each user to a list of uh that user's tweets as well as the count which is uh gonna be used to figure out which tweet was created uh earlier uh and of course we wanna be able to have a follow map to maintain a user and a set of all the people that they follow so i'm actually going to implement the follow and unfollow first because they're a lot easier so for follow we take our follow map and for a follower id we want to say okay this person is now following another person with the uh followee id so with a hash set we're gonna add to that hash set this followee id so that's pretty easy now in the unfollow it's basically the reverse of this right a user is now unfollowing someone so instead of adding we're gonna remove but what if this person is actually not even following a different person well let's just add a conditional to make sure that they are following before we actually call the remove function because at least in python i think it'll throw like an exception or something so let's just make sure if follow e id is in the set for that follower id so if that is the case only then are we actually going to remove it okay so that was the easy part now let's do post tweet it's the second easiest so for any user they just created a tweet so we want to be able to record that
START_SPONSOR_TOKEN before we continue with the video let me just tell you a bit about algomonster as you prepare for your coding interviews on algo monster you'll actually get feedback on which categories you're strong in and which categories you could use a little more practice in you won't be wasting time solving random problems because algomonster has done some intelligent analysis on which categories of problems are asked more frequently and problems also come with solutions to make sure that you don't get stuck they've also got system design and object oriented design content and a bunch more a lot of the features you can actually check out for free but if you do want to subscribe you can get lifetime access and you can get NUMBER_TOKEN off with code neat END_SPONSOR_TOKEN