My Calendar - No Triple Bookings: Interview with a Google Engineer
My Calendar - No Triple Bookings
Watch someone solve the the problem: my calendar ii - no triple bookings problem in an interview with a Google engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.
Interview Summary
Problem type
The Problem: My Calendar II - No Triple Bookings
Interview question
Given a calendar of events represented by start and end times, implement a canAddEvent method that checks whether adding a new event would create a triple booking - a moment in time where three events overlap simultaneously. If adding the event would cause a triple booking, return false without modifying the calendar; otherwise, add the event and return true. The warm-up problem asks simply whether two events overlap, establishing the building block for the main challenge.
Interview Feedback
Feedback about Full Metal Razor (the interviewee)
Advance this person to the next round?
No
How were their technical skills?
3/4
How was their problem solving ability?
2/4
What about their communication ability?
4/4
Strengths:
\* Good clarifying questions at the start and during the main problem \* Coded warmup without issue \* Coded a brute force approach for the main problem \* Good coding hygiene \* Correct time and space complexity analysis
Room for improvement:
\* Make sure to discard ideas quickly using the provided testcases (eg the overlap_count idea would not work for the example provided). Even if going through more examples helps you, try to do it a bit more quickly \* Got a little bogged down trying to come up with a solution for the main problem. Practice more problems of this type to ensure you have the ideas needed in your toolbox \* Typo in code: `calander`
Advice:
\* Do some more problems in the areas that you detect are weak (like intervals). I do always recommend breadth over depth of topics
Feedback about Golden Goblin (the interviewer)
Would you want to work with this person?
Yes
How excited would you be to work with them?
4/4
How good were the questions?
4/4
How helpful was your interviewer in guiding you to the solution(s)?
4/4
Incredible feedback after our session was over, thanks!
Interview Transcript
Full Metal Razor: Hello? Hello, hi. Can you hear me?
Golden Goblin: Yep. Can you hear me?
Full Metal Razor: Yeah, yeah, I can hear you.
Golden Goblin: How are you doing?
Full Metal Razor: I'm doing well. How are you?
Golden Goblin: Doing well, thanks. You scheduled a Google coding interview? Yeah, yeah, I scheduled one. Okay, uh, do you mind sharing if you have any upcoming interviews?
Full Metal Razor: Yeah, I actually have one next week for Google.
Golden Goblin: Okay, sounds good. And what level is this for?
Full Metal Razor: Uh, so I— and this is for an internship, for a summer internship. For internship? Yeah.
Golden Goblin: Okay, okay, sounds good. Anything you want to learn from this practice session?
Full Metal Razor: Um, no, I'm mainly just kind of getting used to doing these interviews. I haven't really done a lot of mocks, so, um, I'm just kind of more so practicing that skill, I guess. Okay.
Golden Goblin: So just general practice and tips. Does that sound good?
Full Metal Razor: Yeah, that's awesome. Yeah, thank you so much.
Golden Goblin: Okay. Yeah. So yeah, we can go over a coding session. So it'll take about 40 minutes. And afterwards, I will go over the feedback that I'll be writing during the interview. And you can also ask any questions that you have. Sound good?
Full Metal Razor: Sounds good. Yeah, sounds great. Thank you.
Golden Goblin: OK, so do you want to select the language that you plan to use?
Full Metal Razor: Oh yeah. So I'll go ahead and I'll use Python here.
Golden Goblin: OK, so let's get started. So to start, let's say we are given 2 events and we want to write a method that returns whether those 2 events overlap or not, so true or false basically.
Full Metal Razor: Okay, okay, um, great. So I guess, uh, my initial question is just how are these events are like represented? Are they from like— is it like a time-based thing or is it like— yeah, I guess that's my first question. Like, how are the events represented?
Golden Goblin: Yeah, so an event is represented by a start time and an end time.
Full Metal Razor: Okay, cool. And would those be like in a list or like in a tuple maybe?
Golden Goblin: You can choose however you You want to represent an event?
Full Metal Razor: Okay, I guess maybe let's just do a list for now, but we could change that later on. Okay, so write a method which returns what? So, okay, so our event is basically we're going to have an input which are going to be our input for this. I'll do this to make it easier. Our input for this method is going to be some, or 2, a pair of events, right? So, We'll have event A and event B. And as we said here, an event is represented like that, start and end time. And then so in terms of overlapping, would— so okay, let's say like event A here is represented by These 2. So I'm assuming we're going to use like integers to represent time here. Is that a fair assumption?
Golden Goblin: Uh, yeah, we can use integers.
Full Metal Razor: Cool. So would something like this be overlapping? Because in this case they share— one has— they share an end time and a start time. Um, so
Golden Goblin: I'm
Full Metal Razor: wondering if I should—
Golden Goblin: The end time is exclusive, so those wouldn't be overlapping.
Full Metal Razor: These are not— okay, so it's explicit. Okay, understood. So these are not overlapping. Okay, great. So,
Golden Goblin: right,
Full Metal Razor: right. But in this situation, this should return true, right? Because—
Golden Goblin: Yep.
Full Metal Razor: Clearly these times are overlapping. Okay, great. Let me try to think if I have any more questions. Yeah, we said they're integers. Are we to assume that it's some positive or non-negative integer that are going to be defining the start and end time?
Golden Goblin: Sorry, can you repeat that?
Full Metal Razor: Oh yeah, yeah. So I was wondering if the start and end time would— should I assume that they're going to be some non-negative integer, or could there be some negative integers as well?
Golden Goblin: Uh, yeah, we can say it's non-negative.
Full Metal Razor: Okay, sure. So start time, or what could it be? Um, okay, great. So yeah, okay, I'm thinking right now we could do a simple check. Um, we could see whether or not the end time of the first event Is later than the start time of the second event, right? So in this example, as you said, it will return true. In this example, this should also return true. Oh, I guess actually, so that only works if the start times are sorted. So I should— should I assume that there's no like ordered start times? to like how the events come, right? So like event A could start before, but event, um, in this situation, but, um, the inverse could be true, right? Where like event A, the first event I'm given, actually starts later. Like this is a valid assumption here.
Golden Goblin: Yeah, yeah, it can be like that.
Full Metal Razor: Okay, cool, cool, cool. So in that case, I think maybe the easiest thing to do would just be to initially get the first event. And so that's a simple check of checking the, the which event here has the smallest start time. And then once we do that, then check. So, we're going to have like now these variables, label event, second event, and this is determined based off of the start times. So, in this case, event B will be our first event and event A will be our second event. And then once we have those 2 events, we can then check the end time of the first, the first event and see if it, um, is greater than the start times of the second event. And so like here's like an example. So like let's say, yeah, let's say we get event A is this, um, pair and event B is this pair. We'll decide that the first event will equal This and the second event will equal this. And this is an O check. And then we'll do another O check determining whether or not the first start time— so if it's greater than the first— sorry, end time is greater than the second event's start time, so 5. So in this case, yeah, this would return true. In this case, so as we said, this would not be overlapping. And so this case it will return false here. And then we could try another case. So like let's say it's like 1, 2. This would also be false here. And I guess we just return this condition, right? And let's try out maybe just something else. You know, we could have some neg— uh, right, we said no negative numbers, but we could have— we could even potentially have something like this, and this would still return false. And even in this case where it's like way larger, this would also return false. It doesn't really matter when this ends. This could end here. Um, although maybe, um, uh, so far I've been doing this assumption, but should I assume that like we have valid events Such that like the end time is at least equal or greater than the start time?
Golden Goblin: Yeah, you can assume that.
Full Metal Razor: Okay, then yeah, this would be a pretty fair system. So, uh, just figuring out which event comes first based off its starting time, then, um, checking the end time of that first event compared to the start time of the second event, and then that'll be a quick way to return. if they overlap. And this is like, each of these comparisons are O because you're only doing content checks each time.
Golden Goblin: Okay, do you want to code it?
Full Metal Razor: Yeah, sure. So we call this— so our goal here, right, is to return overlap I guess we call them events. And then we'll have event A here, event B. Yeah, we'll do the first check. So first event, or we'll do like this. So as we said, the events are defined as defined as a pair in list form. So I guess we can define this start and end. So if event A here, if that start is less than or equal to, because it shouldn't matter if they're equal to each other, Oh, I don't know why I'm writing star here. Uh, compared to event B, then we'll say that the first event is equal to event A. And then otherwise, we could say the first event is equal to event B here. And then we could do the same for second event. Just do the index. Yep. And then here. And then finally, we could simply return the condition of first event. So the end time of the first event, which is represented by the 1 index here, if it's greater than— and has to be strictly greater than in this case, because if they're equal to each other, they're not overlapping— to the second event's start time here. And so yeah, this is a This should be able to handle most cases where we have valid inputs. Yeah, and so I think this should work here. And yeah, it's O complexity in this case for both space and time.
Golden Goblin: Okay, sounds good. So let's move on to the next question. OK. OK. So for this question, we want to maintain a calendar of events, same as before, start and end times. And in this calendar, we want to avoid having a triple booking, which is 3 events happening at the same time, we would like to write a method, canAddEvent, which validates the candidate event against the calendar and checks for triple booking. So if adding this event would create a triple booking, we return false. Otherwise, we add the event to the calendar and return true. So for this example, if we start with an empty calendar, And we call 10:20. There's nothing, so we can just add it. Returns true. 40:60 doesn't overlap with the other one, so we add it. Return true. 10:40, it only overlaps with 10:20, so no triple booking created. Returns true. 5:15, it would create a triple booking with Oh, with 10:20 and 10:40. So because of that, we don't add it to the calendar and return false. Then 5:10, it doesn't overlap with the ones we've added, so it returns true. And lastly, 35:55. Notice that even though it does overlap with 40:60 and with 10:40, It does not introduce a triple booking, so we still add it to the calendar, and then we return true.
Full Metal Razor: OK, cool. So let me just make sure I'm understanding this correctly. I'm going to read over just the prompt again one more time, if that's OK.
Golden Goblin: Yeah, no worries.
Full Metal Razor: Okay, so we said in this situation here where We have start time 35, end time 55. In this case, it's still returning true even though it overlaps with 2 separate events.
Golden Goblin: Right.
Full Metal Razor: And that's the case because these 2 events are not overlapping each other, right?
Golden Goblin: Right. No point in time where all 3 are happening.
Full Metal Razor: Right. But if the example were like this, right? Now these 2 events are overlapping, and so this should return false?
Golden Goblin: Yeah. That's true.
Full Metal Razor: OK. OK. Cool, cool, cool. OK. So I guess I'll kind of run through my own examples just to see how I'm kind of thinking the process is going to work, but let's kind of go through a fresh example. So yeah, we can start off the same with tenants, and I'm going to be writing this down on my kind of scratch paper I have here. Okay. Just so I have a visual guide to help me out, so. Yeah, see, I wanted to take the integers here just to make the logic a little bit easier. I don't want to do this before here. Okay, so this is our first interval, and so obviously we have nothing. Let's say we have maybe some set. I'm not sure yet if we're going to use some set yet, but we We can call this guy calendar. And so in our calendar so far, there's nothing in there, so we could always append our event here. Similarly for the second one, since we know there's only one in there, we could always append this, but it might be good to start checking if these are overlapping. And so let's just do one that is not overlapping. And so let's go 4/8. So now we have 2 events in our calendar here that are non-overlapping events. Now let's add this example here, right? So let's say we have 2 to 6. So now 2 to 6 is pretty interesting because now we have the situation where there are This event overlaps with 2 different sets of events. But of course, this is going to return true because it's not a triple booking. That— this is correct logic, right?
Golden Goblin: Yeah, correct.
Full Metal Razor: Okay, cool. Now finally, let's say I want to add 5 and 7. Or yeah, let's say like 100, right? It doesn't really matter. In this case here, this would return— oh, sorry, this should return— oh my gosh, I did it again. Uh, false, right? Because I'm gonna take a look at all the events that we have in the counter so far. So we have 1, 4, this doesn't overlap. We have 4 and 8, this overlaps. So we can maybe use like some sort of counter here. And so that's plus 1. And then finally we get to 2 and 6 here and we find that 100 overlaps between 6. So that's another event that overlaps, and adding this event will cause a triple booking. And so we wouldn't want to add it. So we should return false and not add it to the calendar. Is that the intention of this program here?
Golden Goblin: Okay. Yeah, that should return false. That's right.
Full Metal Razor: Okay, cool. So initially, I guess I'm thinking so far that we can maybe treat our calendar as some sort of list. And then every time we're able to add an event to the list, we can add that pairing. So, in this initial situation, we'll start off with a blank calendar for the initialization. And then maybe we can go to the next example here, and then we'll check against everything else in the calendar. Since there's nothing there, we don't have anything to check with, so we can always append this event. Then finally, in this next example here, We could take a look at our list again, loop through it, and maybe hold some sort of overlap count. And so, this count will count how many events this event overlaps with. And in this case, it doesn't overlap at all, so we'll return 0. And then we'll append that finally to our list. And then we could do that again, except this case. Hmm. Actually, this example wouldn't really work, and I'll tell you why in a second. But like, let's say we want to add 2 and 6. We could still add 2 and 6 here because it only overlaps once, but by the same kind of concept here, it does work as intended. Because the overlap count will be 2, and we'll know that because, you know, that's 1 away, right? 3 minus 1 equals 2. That's 1 away from overlapping. We wouldn't add it, and so we should return false. However, this wouldn't be the case. Or like, this would be incorrect logic here because let's say like our sets these 2 events were overlap— or not overlapping, right? So let's say it was like 8 and 10 here, right? This would still count 2 overlaps, but it's going to return false anyways and it won't append. Or sorry, yeah, and that's incorrect here because in this case it really should return true if these were the 2 events that are already in our calendar, right?
Golden Goblin: Right.
Full Metal Razor: So yeah, we'll need some other sort of system. And immediately, maybe nothing jumps out to me, but I can maybe kind of think of some solution with some sort of like binary search tree or something where we are indexing off the start time. And then we can maybe check against our event's end time as we go. But I wonder if that would even work. So let's say, like, we, we tried that out, right? So we have 1 and 4 here. And then 4 and 8 starts afterwards. We do 4 and 8 here. Um, maybe in this example here we could have— so 2 and 6, 2 and 6 in this case would come here if we're going to do indexing off of the Start time, and then let's do 5/100, right? And so in this case here, and this is— sorry, I'm kind of muddying my thing. So let's say we want to go down and we check against our Our start time against these end times, right? So, like, hmm, let me try to think this logic through a little bit more. 100. If we go more, so let's say, like, we compare— let's just try comparing the start time to this end time. So we know that 5 is bigger than 100, so that We know that this should go to the right side here. Then when we get here, we're gonna see that 5 is less than 8. And so in this situation, we should check if it's overlapping. Hmm. Okay, so let's say like 100.
Golden Goblin: So you had the idea before about why the 3555 case would return true. Does that tell you about a way you can brute force a solution for the problem? What would be a brute force approach?
Full Metal Razor: Oh, actually, yeah. Oh, brute force a solution. Oh, yeah. OK, OK. Potentially, maybe I could— Instead of looking now for 35 and 55, so like which is the first event that it overlaps with? Okay, actually brute force I could do. So this is the first event overlaps with. We could potentially now look within that scope instead. So like. If 35 and 55 overlaps first with 40 and 60, maybe we should be looking for like within this scope instead. Um, and then we could keep carrying on and see if we overlap with anything else. If we do, then we could return, um, so like check the rest of the list and then return false. If we encounter another overlapping event. And then if not, we would have to check again still because there could be some other cases where 35 and 55 can overlap with another event. Right. So yeah, like we could like— so once we go through that whole thing, we have to go again, start from this next position here, and then check with our original kind of list or event that we're working with, right? So like to walk you through it, maybe let's— so our input here is 35 and 55. And then we're gonna have this calendar here, and I'll just recreate it to make this a little bit better visually. So 40, 60, 10, 40, 5, 15, 5, 10, 10, 35, 55. So yeah, or we haven't added that yet. So With this event, we'll kind of loop through each of these events that are already in our calendar. Once we reach the first one, we're gonna ask like if we overlap. In this case, we don't. So we move on to the next one. Do we overlap? And we do overlap. So when we find an overlap, we do another kind of— Loop. Another scan throughout the array with a bounded event time. So really, we want to bound this or search with this new— with a new start time and this new— with our bounded end time, right? So the max start time and maybe the minimum end time. And then search the rest of the array with that event. So with this new event times, we'll check the next one and it's not overlapping. In this case, we'll check the next one, it's not overlapping. We'll check the next one, it's not overlapping. And then once that's done, we continue again with our normal event. And then, so yeah, with 3555, we'll pick that back up here. We'll check. Are you overlapping? You're not. Or actually, in this case you are. So we'll do it again. And we'll do that with— so this new time. So we said the minimum of the start time and the maximum end time. Or sorry, the maximum of the start time, 35, and the minimum of the end time, which is 40. Yeah, so then we'll check again with this new event pair. And so we'll check the next one. We'll go, no, you're not overlapping. No, you're not overlapping. Once again, we'll continue with 35, continue down the rest of the array, and then end right there. So yeah, that's maybe a brute force solution that could possibly work, but obviously that's pretty inefficient because let's say, like, for example, we find an overlapping event each in each num or like in each slot of our array. We could potentially be scanning the array every single time we pass a new one. So that would be O solution here, right?
Golden Goblin: Right.
Full Metal Razor: But yeah, that's kind of the initial idea.
Golden Goblin: Okay, um, do you want to take a minute to see if you find a way to improve the efficiency of that, or do you want to code it? Yeah, sure.
Full Metal Razor: Um, yeah, I could, um, start thinking of maybe a different way, and if I don't have anything, then I'll start coding the solution.
Golden Goblin: Okay, sounds good.
Full Metal Razor: Right now I'm thinking maybe like there could be some use in having some sort of sorted calendar, because that'll be a quick way to kind of determine— we might not have to scan the whole thing. So maybe let's like try to do this example with some sort of sorted array. And we could sort by start time. Let's try. And so yeah, if we're trying to put 35 and 55, Because the thing is we have to worry both about— or do we have to worry both about start and end time? Maybe we can just all worry about the end time. Right, because we defined our comparison here by the end time. So Hmm, yeah. Yeah, I guess nothing's really coming to mind. Um, there might be some sort of new ones, but actually right now I don't have anything else in mind. So for the sake of time, do you want me to start the presentation?
Golden Goblin: Uh, yeah, let's do that.
Full Metal Razor: Sure. So, we'd have this event here called an add event, and we're gonna have start time and end time here, right? Because we initially displayed them as that, and I should assume that, like, these are valid integers and they're not Hello, sorry.
Golden Goblin: Uh, hello, sorry, it cut off for a bit. Can you repeat that question?
Full Metal Razor: Yeah, you're good. Uh, I'm just wondering, can I make the same assumptions for start and end here as I made for like the previous, um, method that you wrote up?
Golden Goblin: Oh yeah, for sure. Yeah.
Full Metal Razor: Okay, cool. So, okay, I guess we should make— yeah, a class. We'll call it Calendar class, and then we'll have— Right here. So we'll have our calendar here, and we set this calendar right now. Is represented as a list. Yep. So then we want to add events. We do the checks that I said. And so we're going to loop through for event in calendar. Now we're looping through this entire array. Let's pretend that— let's bring these guys down here to help me out to visualize. So yeah, let's say we have this full thing. We're gonna do as we said, so we're gonna loop through each of these events, and then let me bring over our old method that we wrote earlier. So yeah, each of these moments we're gonna ask, okay, if our events that we want to input here, so we define them as a list in our previous method, we're gonna ask if it's overlapping. So we're gonna call this— I got like some sort of disconnection error. I don't know if you— Yeah, I'm getting the same thing. I saw that too. I don't think it's me typing.
Golden Goblin: Yeah, but I can still see you typing, so I think it—
Full Metal Razor: Okay.
Golden Goblin: It lags for me, but it's
Full Metal Razor: okay. Okay, okay, sounds good. Um, so yeah, we want to ask like, are these 2 events overlapping? And so if, if they are, then we have to do what I said before. And so we have to take basically our like, uh, new start is going to be the I think we defined as the maximum between the start that we're given for the event that we want to put in and then the event that we're currently looking at. So event as index 0, and then a new end here is going to basically be equal to the minimum of the end and the event's end. And so this will allow us to see if anything else falls within this range. then we know that we have a triple booking here. So, now with this new kind of event bounds, we're gonna scan through the array again, and I'm gonna enumerate this so that we have access to the index. And now that we can do that, we can start looking at all the values, all the events in front of us right now. So, we'll start from i plus 1. All the way till the length of self.calendar. So as we do this, we're essentially going to be looking ahead. So, right, um, let's say like we found an overlapping event here. This is index, uh, 1 here. And so we're looking at now, uh, starting from index 2 onwards and asking if these— this new event is overlapping with those events, right? So if that is the case, then we should return false. And so what that looks like is gonna be calling our method that we wrote up here, self.event_exists. We're gonna call it with our new bounded event. And we're gonna be comparing that with The index that we are currently at, which is j. So yeah, if this is truly overlapping, then we should return false. In that case, this whole method will stop and we wouldn't add anything to our calendar. And— Bing. Scribbly line here. Oh yeah. And so then finally, once this is fully looking, then we're done looking with that new bounded event and we'll start over from the next position that we were originally looking at once we found the overlapping event. So, let's say we found the overlapping event here, we'll start up the outer for loop again in this next index. And finally, if we go through the entire array without finding any of those triple overlaps, then we could return true. And before we do that, we should add to our calendar this new event and we have them. So, right now initialized as a pair within a list. So, we'll do the same here, um, and we'll do .text. And yeah, so maybe we could go through like a quick example, um, unless you want to add anything first before we do that.
Golden Goblin: Um, Yeah, I think that looks good.
Full Metal Razor: Okay. Yeah, we can go through like a quick example to see what— if it does truly work. So yeah, we're gonna have 1 and 4 here, and we're gonna ask can add event. And so it's gonna try to enumerate through our calendar, but our calendar list is currently empty based off of our initialization here. So then this won't even run. And so we'll append this new start time to our calendar and return true. So now we're looking at 1 and 4. Now we'll try— we'll just go straight to the point. We'll do another overlapping event. We'll do 2 and 5 and we'll see what this returns. So when we do 2 and 5 here, we're going to once again loop through the calendar. We're going to ask, are these events overlapping? So we'll try 2 and 1 and 5 with the current event that we're at, which is 1 and 4. And then this should return to us true that it is overlapping. And so we'll go through this case and we'll have the new modified event that we're looking at. So we're going to be looking at the new modified event of the max between the starts, which is 2, and the minimum between the ends, which is 4. And so if anything— if it doesn't exist, anything that overlaps with this, we know the option is working. Although in this case, we're going to find that there's no other events in our list, and so this is not even going to run. And so then we'll go back to the for loop and we'll basically terminate here at the end of the list, and then we're going to be able to append to our calendar and return true as well. Now finally here, let's just append. Finally here, we could add Another example of us trying to do 3 and 6, and we'll see what happens there. So we're going to loop through again, once again, the calendar. We're going to ask if these events overlap, and initially it is going to overlap with 1 and 4. So now we're going to have to look again, but now with the new bounded event time. And so we'll do 3 and 4 here, and if anything overlaps with this event, then we should be returning. False. And so, it's going to look ahead towards the next— the index after i, which is going to be 2 and 5 here. I'm going to ask if 2 and 5 is overlapping with our new bounded time, 3 and 4. And in this case, it actually does overlap. And so, we're going to return false, not append anything to counter. So, counter does not make any changes here. And then finally, let's just make sure it works with an event that does not overlap at all. We'll do 0 and 0 just to really see, like, make sure this works. So we'll go through here. We're going to loop through all the current events in our calendar. So as I said, calendar doesn't change. We go through 1 and 4. Does 1 and 4 overlap with 0 and 0? In this case, no, it doesn't. So we'll go on to 2 and 5. It doesn't overlap. And so we could append finally to our calendar and return true. And so, yeah, as I said, this is a somewhat inefficient method here because every time, as we noticed, you find an overlapping event, you're gonna have to continue throughout the whole array again. And that can happen perhaps at every single— what's it called— every single item in our calendar list. Like if you have something like 0 and 100. they would overlap with all these. And so at each moment, we're going to have to run through the other for this. And so yeah, this is an O of n squared time approach and a space approach of O of n, which is going to be all the valid events in our calendar. Yeah.
Golden Goblin: OK. OK. Sounds good. So I think we can probably stop here with the coding session, if that's OK. And then we can go over feedback. Does that sound good?
Full Metal Razor: Yeah, that sounds good. I really want to know how to do this problem. More efficiently. Yeah, yeah.
Golden Goblin: I mean, I can start with that so that you know if I can start with that. So you almost had like a. I mean, you almost had it here because you computed the overlap, right? So one of the ideas here to make it more efficient can be. What if you keep, like, store not just the calendar events, but also the existing overlaps? So whenever you're about to add an event to the calendar, instead of having to check basically a double loop, you would just check that event against the overlaps that you have, right? If it overlaps with any of the existing overlaps, then you know that there's triple booking, so you return false. But if it doesn't, then you can, you can add it. So to add it, you add it to the calendar, and you also add any new overlaps that you find to the To the overlaps array and then you, you return true. Um,
Full Metal Razor: oh, so, oh, so you're saying that we have like another kind of data structure here that holds on to all the overlapping like kind of, um, start and end times? Is that what you're saying? Right. I see. Oh, that's, oh, that's, that's good. That's good. That's really good. Dang.
Golden Goblin: Yeah, so I would say that's the— that's one. Like, there's another approach too, but I mean, this is the one that would be closer to your train of thought, I guess. The other— another approach here would be a line sweep. I don't know if you're familiar with that.
Full Metal Razor: Oh no, I'm not familiar with that one. I've only heard of that before, but I never took the time to like look at it.
Golden Goblin: Okay, but basically the idea is you're gonna, like, let's say you have all the timestamps, right, for the events, the start and end times. Yeah. And so what LightSweep does is you process those times in sorted order. And so basically, at start time, you add 1 to your current event counter. If you encounter an end time, you subtract 1 from the current event counter. And so given all the events, you will have a triple booking if the counter reaches 3.
Full Metal Razor: Okay, so you kind of— would you have like some sort of like— is it like a map with like really the keys are the start and end times, but they're sorted? And that,
Golden Goblin: uh, you have like a just a— it's just a vector, but it's sorted by the timestamp. Um,
Full Metal Razor: okay, okay.
Golden Goblin: And then you can just— I mean, you can use a, a pair just so that you know which one is start time, which one is end time. That's what you need. But yeah, so that would be one.
Full Metal Razor: Yeah.
Golden Goblin: So that would be another more efficient approach.
Full Metal Razor: Yeah.
Golden Goblin: And like, you could keep it— you could compute it as you go and sort every time, which is a little inefficient, but like still better than n squared. Or you can just keep a sorted list as part of your data structures, which would make it O, similar to the array strategy. Um, so, well, both of them can be, can be like more efficient solutions, um,
Full Metal Razor: than O.
Golden Goblin: Does that, does that make sense?
Full Metal Razor: Yeah, yeah, that makes sense. Oh yeah, I gotta look into that, uh, line sweep. I've never actually looked into it before, but yeah, that makes a lot of sense. I'm actually glad we did like an interval question because I'm not like— this is— I'm really shaky on these, so this is like a good Turning moment for me.
Golden Goblin: Yeah, no worries. Hopefully it's helpful. So let me just go over the feedback before we discuss more. So I would say a few strengths, good clarifying questions, both, I would say both at the start and during the main, during the main problem as well. I think you did pretty good at clarifying the requirements before you start. I think, yeah, that was really well done. Yeah. Then also, warm-up problem, you didn't have trouble coming up with a solution, and you coded it quickly. So that was good, a good start. Then I would say you coded a brute force approach for the main problem. It was like you didn't have issues with coding there. And generally good coding hygiene in terms of the naming and like, like obviously for Python you kind of need to do indentation properly, but it was—
Full Metal Razor: Yeah.
Golden Goblin: Generally clear code. And then lastly, good, good on the time and space complexity analysis. You went over it at the end. I didn't even have to ask. I guess saves a little bit of time if you just say it yourself. So yeah, I think those were some good points. The other— the main, the main places where there's room for improvement is basically kind of the idea generation, I would say. So a couple of things. One is you had the idea for the overlap count. And I feel like you sort of had a— I think you had the intuition that it was not going to work, but you still tried to fit it into the problem. And notice that, I mean, the naive overlap count doesn't work. For the provided example, because that's why we have the 35, 55 there. And I mean, in general for this problem, it's relatively easy to be like, oh yeah, actually you can have an event that overlaps with all the previous events, but generally it's not triple booking if all of those previous events are not overlapping themselves. And so anything that tries to count overlaps from the new event. That's not gonna— that's gonna work on its own. So I would be like, okay, so if you know that idea is not gonna work, let's just kind of discard it. And I mean, you can point it out during the interview and say why you're like not going with it and yeah, kind of move on with it quickly. So that's kind of part of the art of the interview, right? Like, you have to,
Full Metal Razor: you
Golden Goblin: know, like, find ideas. It's good. But then also have, you know, an adversarial mindset where you're trying to shoot down your own ideas, whether it is with the provided test cases, if there's a good amount, or with your own test cases. Like, think about, oh, is there an example— can I come up with an example where this idea would not work? And so do your best at coming up with that example as fast as you can. And that way you can be like, okay, either I found somewhere where it doesn't work, or, oh, now I'm pretty confident that it does work because, like, I, I did my best to find an example and it, it, I just couldn't come up with it. I think this idea is correct. And then also that helps you understand why the idea works.
Full Metal Razor: Yeah.
Golden Goblin: When you try to come up with an example where it doesn't work. So,
Full Metal Razor: right,
Golden Goblin: that's, yeah, that's one thing. And then I would say you also, I mean, got a little bogged down trying to come up with a solution. So that's why I steered you towards, I steered you towards brute force because I knew you could you can get the brute force. Um, so I would suggest in general during the, the interview, keep the, keep the clock in mind. Um,
Full Metal Razor: yeah.
Golden Goblin: And so if you get stuck, there's a few things you can do to try to get unstuck. One is, okay, let's go over various common algorithms and data structures that can be that are commonly asked, and can I apply each of those to this problem? Like, is there, is there some, something there that I can try to apply?
Full Metal Razor: Okay.
Golden Goblin: Another is to just be like, okay, I'm not seeing a solution, let's just try to find some simple brute force approach. And the key there would be like, okay, if I find the brute force, then maybe you'll be less stressed about finding a more efficient solution. And also, worst case, like we did here, worst case, if you don't find a better solution, you can just go ahead and code the brute force. For the Google interview, it's pretty important to code something by the end of the interview. Yeah. So what we did here of coding the brute force, I mean, it's not the best performance, but you still coded something, so it's not like—
Full Metal Razor: Right.
Golden Goblin: Not the worst either.
Full Metal Razor: Yeah.
Golden Goblin: Does that make sense?
Full Metal Razor: Yeah,
Golden Goblin: that makes
Full Metal Razor: sense.
Golden Goblin: So that's, that's still better than spending the entire time trying to find the efficient solution.
Full Metal Razor: Yeah.
Golden Goblin: And, and the last thing, which I mean can be like a last resort if you feel like you're pretty close but like you need maybe a little bit of nudging, can be like Okay, you show, or you've been showing your interviewer all the ideas that you had, and like you may kind of ask them, oh, is there any of these ideas do you think that would be worth pursuing further? Or kind of asking them like if they can give you a small hint in the right direction. That can sometimes help.
Full Metal Razor: How negatively though does that look? If I do that, like if I'm just like, oh, like if I go through everything, I'm like, oh, is there anything you think I should go like look further into? Like, I don't know, is that seen as like a negative thing or like a somewhat negative thing, but like, I don't know, manageable?
Golden Goblin: Obviously, ideally, ideally you just come up with the answer on your own without hints. That would be the ideal. scenario. But sometimes, sometimes you're kind of close, but— or like if you feel you're kind of close, but you just haven't quite gotten it, it can be useful to see if the interviewer will nudge you and tell you like, oh, consider this or that. I would say depends on the interviewer too. Some of them may be very hands-off, and if they've been like super quiet and haven't helped you at all during the entire interview, then you might just nudge them to be like, oh, help me out a little because I'm stuck. Yeah. But if they've already kind of been helping you out, I mean, maybe less. less useful to ask them for a hint. Yeah. So, yeah, it's more of a— in general, more of a last resort kind of thing, I would say.
Full Metal Razor: Right. Yeah.
Golden Goblin: It's better to just obviously avoid asking for hints directly.
Full Metal Razor: Yeah.
Golden Goblin: But if it's between that and not coding anything, then it's better to— Yeah, to just ask for it.
Full Metal Razor: Fair.
Golden Goblin: Um, yeah, and then the— so those were just like, I guess, the 2 main things basically. Uh, comes down to like discarding ideas quickly, um, kind of coming up with more ideas, and like timing, right? Like making sure you're making progress. I mean, you did well with the warm-up problem, but for the main problem, you were stuck for a while. So just trying to make sure you keep an eye on timing is useful. And then a small last thing. There's a typo in one of your variables, calendar.
Full Metal Razor: Oh, really? Yeah.
Golden Goblin: Which I mean, it's— It's not a big deal.
Full Metal Razor: Yeah, that's a hard word for me to spell. I always get it wrong. But yeah, thank you for pointing that out.
Golden Goblin: Oh yeah, no worries. So obviously it wouldn't affect much, but yeah, I mean, just for— yeah, you had it right here. Calendar. Yep. So you had it right here. But then you got it wrong at the other places.
Full Metal Razor: Yeah.
Golden Goblin: So overall for this problem, I would say generally it's kind of expected to try to code some things a bit better than the brute force approach.
Full Metal Razor: Yeah.
Golden Goblin: So obviously coding the brute force is like, I guess, the next best thing. But it still would, would have, would have been better to see you kind of come up with a little more ideas for the problem. And maybe, maybe it's what you mentioned that, oh, maybe you're missing some practice with interval problems. Yeah. Which is, which is obviously, um, something that can be easily improved. Just do a few interval problems to get that confidence and those kind of ideas that would let you solve this type of problem. Um, I would recommend doing like a variety of problems instead of focusing on a specific area, but obviously if you see you have a weak area you can do a couple of, you can do a couple of problems in that area just to kind of get better there. Um, because honestly, interval problems, I mean, they're maybe not as common as graph problems, but they can be fairly common, right? Um, so it's good to be prepared for those.
Full Metal Razor: I kind of like what— because I, I don't have a lot of experience with doing this, um, I guess, type of coding, uh, like [REDACTED] type of questions, because I guess like my first internship really that like season I'm applying for. So, um, I was focusing a lot on like, I know Google asks a lot about like graphs and trees and stuff like that, so, and arrays. So I was really focusing on like those sections, and that's kind of why like I didn't look at intervals too much, but I've been trying to get them more into my like practice recently.
Golden Goblin: Yeah, and, uh, sorry, when did you say you have your interview?
Full Metal Razor: It's in a week.
Golden Goblin: Okay, so you still have, like, you still have some time, uh, to practice, I think.
Full Metal Razor: Yeah.
Golden Goblin: I mean, I think you could still get— fill in some of those gaps if, like, within a week. It's not, it's not like a dire situation where you're like, oh, Um, because like communication-wise you're doing really well, uh, so keep that communication part. Um, and I think, um, yeah, maybe if I had given you a graph problem I would be like, oh yeah, you're super ready. Um, I don't know, but, but, uh, yeah, the thing is you don't know what problem you're getting. Um, right, it's always good to To cover all your bases for at least for the common, common topics that you can get. So you, you said you already did a bunch of graph and arrays, so that's good. Also do some strings because string problems can come up sometimes. And then since we detected intervals can be a source of weakness, um, yeah, also do a few interval problems. That way you can kind of get I mean, there's a few ideas that you can just understand and have under your belt so that way when you get the next problem of that type, then you can kind of associate it, right? And then that's, that's how you get the problem solved. So yeah, hopefully that helps. Any questions before we wrap up?
Full Metal Razor: Um, no, honestly, that was like very helpful. I appreciate the guidance. That was very in-depth. Because I think a big thing of mine is that sometimes I really do find it hard to generate the idea immediately. And I guess that's why it kind of gets sometimes bogged down and trying out an example, even though I know it's probably not correct, just because I don't know. I got to know if— it's hard for me to just say, I know this isn't going to work, so I should stop looking at it. Because sometimes I do find that it is helpful to maybe think of it, and like going through an example helps them realize that like, oh, I shouldn't be looking at that, I should be looking at this instead. So, um, right, I don't know. But yeah, I think a lot of the points that you have, like trying to go over like each of the common data structures or algorithms and seeing if that could be applied, is helpful. Um, but yeah, I think that's kind of— that's the biggest thing I'd worry about. Yeah.
Golden Goblin: Yeah, for sure. And maybe like Once you practice, if it helps you to go through the example, even for an idea you're not super confident in, just practice doing it quickly.
Full Metal Razor: OK.
Golden Goblin: Yeah. So part of the problem I'm seeing is, OK, we need to speed up the determining if an idea is going to work or not. And so it's OK, whatever method you pick. I mean, it's OK you use an example. That's fine. But, well, if you use an example, make sure you do it quickly. You don't want to spend, like, too much time thinking, oh, is this incorrect idea going to work?
Full Metal Razor: Yeah.
Golden Goblin: So that's kind of the key is, like, okay, do whatever you feel is, like, you're most comfortable with to, you know, determine if it's going to work or not. But practice doing it relatively quickly. And even if, uh, in this case, I would say even if you don't explain it super fully to the interviewer, because the interviewer knows the problem really well, so they will likely follow you. And especially if you're just discarding an idea that is like testing if an idea is correct or not, they don't need to follow. You don't need to like, you know, tell them every single detail.
Full Metal Razor: Point of view. If that makes sense. Yeah. Yeah, that makes sense.
Golden Goblin: And so you can, yeah, you can practice it, like find ways to make that a little faster, and I think that will help you a lot.
Full Metal Razor: Okay, that's a great point. Yeah, that's actually really good. Okay, I will definitely follow that idea.
Golden Goblin: All right, well, uh, good luck in your upcoming interview and have a great rest of your day.
Full Metal Razor: Yeah, thank you. You too. I appreciate all the advice. Have a good one.
Golden Goblin: You too. Bye.
\ \ Microsoft Interviewer\ \ Unique ID generation\ \ Invincible Cloud,aMicrosoftengineer, interviewed Golden Possum\ \ Watch interview](/content/mocks/microsoft-system-design-unique-id-generation/index.html)
\ \ Google Interviewer\ \ Order statistic of an unsorted array\ \ Intergalactic Avenger,aGoogleengineer, interviewed Supersonic Taco in Java\ \ Watch interview](/content/mocks/google-java-order-statistic-of-an-unsorted-array/index.html)
\ \ Google Interviewer\ \ Most frequent integer and pairs of integers sum\ \ Paisley Wallaby,aGoogleengineer, interviewed Propitious Bear in Java\ \ Watch interview](/content/mocks/google-java-most-frequent-integer-and-pairs-of-integers-sum/index.html)
\ \ Google Interviewer\ \ Triplet Array\ \ Rocket Wind,aGoogleengineer, interviewed Whirlwind Alligator in C#\ \ Watch interview](/content/mocks/triplet-array/index.html)
We know exactly what to do and say to get the company, title, and salary you want.
Interview prep and job hunting are chaos and pain. We can help. Really.
Get started for free