Interview Transcript
Ferocious Lightning: Hello. Hi, can you hear me? Yes, I can hear you well. How are you doing?
Distinguished Dromedary: Good, how are you?
Ferocious Lightning: Not bad, not bad. Okay, so let me explain how we're going to go about this session. We'll take about 5 minutes for some intros, then we'll do 45 minutes for some problem solving, and 10 minutes for some feedback questions and going over how we perform during the session. Does that sound good?
Distinguished Dromedary: That sounds good, yeah.
Ferocious Lightning: Okay, great. So why don't you tell me a little bit about yourself?
Distinguished Dromedary: Sure, yeah. I'm a software engineer. I've been working at [REDACTED] for about 3.5 years now. And yeah, I mean, I build like full-stack web applications focusing on boosting productivity and also like analytics platforms. And yeah, I mean, I guess I'm doing this session because I have an interview coming up in a little over a week with [REDACTED]. So I just wanted to get some practice in, I would say. My main areas of focus are probably like time management and edge cases for technical problems.
Ferocious Lightning: Okay, that's great. Thanks for that explanation. So a little bit about myself, I'm a software engineer. I got about 20 years of experience. Right now I'm working at a big tech company as a backend engineer. And I'm working in a product that integrates with GenAI to assist in customer service workflows. That's kind of in a nutshell what I am doing. Okay, let's do the following. You mentioned you're going for [REDACTED]. Do you mind me asking which level you're applying to?
Distinguished Dromedary: [REDACTED]
Ferocious Lightning: Okay. That's cool. All right, I mean, what I can tell you, 'cause based on what I know about [REDACTED], in case you don't know, they're gonna target a single hard problem during the whole session, during a 40-minute or so amount of time that you're gonna have to get to a solution. So we can do this most probably, sometimes it's a medium, most likely it's going to be a hard problem. So what we can do is either I can give you a few mediums or start with an easy and then transition to a hard problem, or just go straight into the hard problem. Up to you how you want to go about it.
Distinguished Dromedary: Um, I think we can go straight into a hard problem. I have been practicing a decent amount. Um, so yeah, I mean, I think we can try to attempt something like that.
Ferocious Lightning: Okay, sure enough. Okay, give me a minute while I prepare the problem. In the meantime, why don't you select the language you want to code in. Coding.
Distinguished Dromedary: Okay.
Ferocious Lightning: All right. Okay, so bear with me a second. You wanna, you wanna select the coding language you're gonna use?
Distinguished Dromedary: Yeah, I want to use Python. Let me just change it. Okay.
Ferocious Lightning: Great. OK. Let me just get this out of the way. I think this is how you make comments in Python. I'm more of a JavaScript guy, but don't judge me for that.
Distinguished Dromedary: OK.
Ferocious Lightning: All right. And I'm going to post some examples. All right, take your time to read through it and let me know when you're ready to get started.
Distinguished Dromedary: Okay. So, "The US Office of Energy is on a future— man has developed faster-than-light travel, enabling it to reach almost any place in the universe. However, this technology faces insurmountable challenges, such as travel times and space sickness." Expedition is visiting the unknown mysterious region on a cosmic spaceship. In front of us is a black hole that spins. At its earlymost stage, scientists have figured out how to activate the device, but it consumes a tremendous amount of energy with every use, making it impractical. Here is where you come in. NASA is developing an efficient algorithm that can count the number of black holes in a region of space in the most efficient way. Researchers have connected the device to a data center, extracting its functionality. You will be given coordinates for a 2-dimensional area of space represented by the bottom left and bottom— bottom left and top right corner coordinates. So coordinates are expressed in integers, x, y pairs. So bottom left, bottom x, bottom left y. Top right x, top right y. You will also be provided with a device that exposes a function. So bottom left, top right, it's a Boolean. This function takes the bottom left, top right coordinates of a 2-dimensional area. If one or more black holes are present within the region, it returns true. Otherwise, it returns false. So humanity belongs—okay.
Ferocious Lightning: Just one thing, sorry, your microphone is a little bit muffled. If you can talk a little bit, move it to talk a little closer to it.
Distinguished Dromedary: Yeah, can you hear me now?
Ferocious Lightning: That's a little better, yes.
Distinguished Dromedary: Okay, yeah, let me know if I need to, I can try to put on headphones or something.
Ferocious Lightning: Yeah.
Distinguished Dromedary: So okay, let me try to restate the problem here. So we're given a grid here and we're given also a function, the device that BlackHoles presents, and you can give it essentially two coordinates that form— that form a grid, and then when you give it those two coordinates, it'll return back a Boolean whether a black hole is present in this grid, correct?
Ferocious Lightning: Correct.
Distinguished Dromedary: Okay, so let's try to run through some examples here. For example 1, we're given a— so we're given a 10 by 9 grid grid, and then the black holes are present at 2, 3, 5, 1, and 7, 8. And then example 2 here, black holes are present at 4, 4, and 5, 5. Okay, so some questions I'm going to start off with. So when we're being given— so to our problem, what are the inputs here? Are we just being given like just the top, bottom— what is it? The bottom left and top right coordinates of the entire grid is what we're being given?
Ferocious Lightning: Yes.
Distinguished Dromedary: OK. So I'm assuming, let me just map out down here, take some notes. So the inputs, and then I guess will these inputs be, so like I can assume like bottom X, bottom Y, and then top X, top Y? Does that sound correct?
Ferocious Lightning: Yes.
Distinguished Dromedary: And then the output, I'm assuming we want a list, so just a list of coordinates, so a list of the XY pairs. Is that correct? Where the black holes are present?
Ferocious Lightning: Not exactly. See if you can read the problem again.
Distinguished Dromedary: OK. So this function takes in bottom left, top right coordinates. If one or more black holes are present within the region, it returns true. Otherwise, it returns false. OK. So we are actually outputting a Boolean.
Ferocious Lightning: I'll give you a hand. Read line 6.
Distinguished Dromedary: Your task is to develop an efficient algorithm that can count the number of black holes, abstracting its functionality into a service that you can interact with. So yeah, we're developing an algorithm— we're developing a function But the output of that function will be a Boolean, correct?
Ferocious Lightning: No, you can output— okay, you can output the list of coordinates or you can output the count. I'm fine with either. You can do the count for now.
Distinguished Dromedary: Okay, so count. So this is coordinates or count. Yeah, I think I got mixed up with the helper functions. The helper function returns a Boolean, but our function, I guess, yeah, line 6 can count the number of black holes in the region. So count. Okay. And then I guess some of— I guess the constraints on this. So constraints, so on this matrix, like, how large can we assume this matrix is?
Ferocious Lightning: From 0 to 1,000, you can assume it fits in memory.
Distinguished Dromedary: So it can go up to 1,000 cells?
Ferocious Lightning: The cardinality of the coordinates, like the range of the values of each coordinate, it goes from 0 to 1,000.
Distinguished Dromedary: Okay, so 0 to 1,000. And this is for x and y?
Ferocious Lightning: Yes.
Distinguished Dromedary: Okay, so in theory we could— The bottom X and bottom Y could equal the top X and top Y, correct?
Ferocious Lightning: Yes.
Distinguished Dromedary: Okay. And so the outputs are counts. So our outputs, in theory there could be zero black holes in in this range, correct?
Ferocious Lightning: Yes.
Distinguished Dromedary: So for the output, for our count, which is the output, it can be zero. So I'm assuming since these go up to 1,000, the count can also go up to 1,000 then?
Ferocious Lightning: Yes.
Distinguished Dromedary: Okay, so pounds. Let me just verify that these are equals. Can also go up to 1,000. Okay. And yeah, I guess we basically need to just figure out if there are— So how many there are? Yeah, I mean, I guess the brute force, if you want me to just talk through what I think about here, like the brute force would be— also just one more clarifying question. So when I'm using this BlackHolePresent, bottom left and top right.
Ferocious Lightning: Yes.
Distinguished Dromedary: If I put in the same value here, so let's say for example 1, let's say I put in 2, 3 for the bottom left and 2, 3 for the top right, will that output, will that be fine and will it also output true?
Ferocious Lightning: Correct, yes.
Distinguished Dromedary: Okay, so it'll check that exact cell. So yeah, I guess one of—
Ferocious Lightning: Hello?
Distinguished Dromedary: Can you hear me?
Ferocious Lightning: You just disconnected. Can you repeat that?
Distinguished Dromedary: Okay. So the brute force solution, which I think this can be optimized, is basically checking every single cell. So, you know, that would be check every single cell between the bottom left and top right. And yeah, basically just keeping track of a count variable. And yeah, that would require us to go through all the cells. And yeah, I mean, it's— that solution also wouldn't work for all cases because it says on the bottom here that, you know, the—at most we can make 400 calls. So that's just like the initial of what I'm thinking. But then— and then that would be like an O(n) O(n) time algorithm, and then I think an O(1)—an O(1) space algorithm because all we're really keeping track of is counts. But it wouldn't work for all cases because again, we only have 400 calls and then, you know, our cells could theoretically be up to 1,000. So what I'm thinking about to optimize this would be— A binary search. So, you know, like let's say for instance, like let's say we're looking at example 1. So we call 0, 0, and then we call the top right, which I guess in this example would be given 10, 9, correct?
Ferocious Lightning: Mm-hmm.
Distinguished Dromedary: So we call that. If that output's false, we don't need to check anything anymore. Our count is 0. Like, we can just stop there. Now if it outputs true, then we can essentially split our matrix, correct? Like, we can check, we can find the middle value here, and then we recursively call binary search. So like, you know, for here we can give it the bounds 0, 0, and then, so I guess the middle value would be 5, 4.
Ferocious Lightning: Mm-hmm.
Distinguished Dromedary: And then again, call our recursive function and then check like, okay, like, is does this have a black hole? So where we're calling— so just to be clear in this example, for instance, we start with— so our first, I guess, first recursive call, we start with 0 and then 00 and 10, 9. 10, 9, or actually 9, 10.
Ferocious Lightning: Mm-hmm.
Distinguished Dromedary: Excellent. So our second recursive call, and these will actually be broken up into two. So our second recursive call is then gonna check the mid, we're gonna find the midpoint and then we're gonna check those. So it's going to be 0, 0. So it's going to go up to 4, 5. And then also we're going to go from— so we need to go from, I guess, here 5, So let me think about this here. So it's going to break this up into squares. So if we call this function, we essentially need to break— not break this up into 2, we need to break this up into 4.
Ferocious Lightning: Yeah.
Distinguished Dromedary: So we would need to then call— so let's see here. So we are at 4— so we are here, 4, 5. So we need to call then 5— So we're going over 1, so 55, so 55 down to 9-0, 55 down to 9-0, and then yes, so 5-5, 5, we would want to go like 6, 6 up to the top, so 9, 10. And then we would want to go, so 4, 5, we would want to go Like 4, 6 up to— that would be 0, 10. And then so these functions will then— so, you know, for instance, in our first recursive call, if we had just gotten 0, we would just return 0. But obviously we had gotten true, so now we're going to second recursive call. And then basically our base case will be if we keep on returning true, our base case will be when we get to a point where the coordinates are equal to each other. And then at that point, you know, we return 1 if it's true, 0 if it's false. Does that— does that make sense?
Ferocious Lightning: Yeah, I think we're getting there. This is good. Could you just review the coordinates of line 41 just to make crystal clear what we're doing here? It is the right approach in my opinion, but I'm a little confused about the coordinates.
Distinguished Dromedary: Sure. So we're essentially creating 4 different screens. Squares now since we have returned true from our first recursive call.
Ferocious Lightning: Yeah.
Distinguished Dromedary: So that's basically what I'm trying to do here is this first one should be the bottom left square.
Ferocious Lightning: Yeah.
Distinguished Dromedary: So it should go from 0, 0 to 4, 5. So we've calculated basically a middle coordinate. And then the second one here, 5, 5 to 9, 0, that should be the bottom right square.
Ferocious Lightning: OK, so that's confusing me a little bit. I understand what you're saying. You're saying 5, 5— which one are you— what order? Are you doing bottom left, top right?
Distinguished Dromedary: Oh, I think I messed up the— I guess since the function takes in bottom— so it takes in bottom left to top right. OK, so let me actually fix this here. So for that to be bottom left, we would need to start at 5, 0, and then for this to be the bottom right, and then this would need to go up to 9— this would need to go up to 9, 5. So this is the bottom right now. And then let me fix this right here too. So this would need— so for this to be the bottom left, so this goes up to 4 or 5 here. So for this to be the top right, we would need to start at— so it goes up to 4 or 5, and then this should already be This should already be covered in the bottom left. So we need to start at 5, 6. So start at 5, 6 and then go all the way up to 9, 10. And then for the last one to be the top left, we would need to start at— so again, we ended at 4, 5. So for that to be the bottom left, We would need to start at 6-0, or yeah, so now I'm calculating the top left, and then this would need to go up to, so let's see here, we go up to 4-5, and then our top right starts at 5-6, so this would need to go up— to 410. Does that make sense now? Now that I've like fixed the conventions?
Ferocious Lightning: Uh, 60 to 4— it seems you're going backwards. Hold on, I'm sorry. 60— To— —and then 410.
Distinguished Dromedary: Yeah, so this 60 would be the bottom left.— and then 4, 10 would be—
Ferocious Lightning: I think you're mixing the x and y axes.
Distinguished Dromedary: Oh, yeah. So that would be 0, 6. 0, 6.
Ferocious Lightning: Yeah, that makes more sense, yeah. Yeah.
Distinguished Dromedary: And—
Ferocious Lightning: Yeah, go ahead.
Distinguished Dromedary: Let me just see here if I mixed up the x and y anywhere else.
Ferocious Lightning: So the last one is the bottom right quadrant, right?
Distinguished Dromedary: Uh, the last one?
Ferocious Lightning: The left, yeah, that, yeah.
Distinguished Dromedary: That should be the top left quadrant. So we're starting at—
Ferocious Lightning: Oh, okay, I see. 06, all right, now I got you. And 14, okay, now I got you, yeah, okay.
Distinguished Dromedary: Okay, so this is bottom, just so we're on the same page, this is bottom left quadrant. This is bottom right quadrant. This is the top right quadrant, and then this is the top left quadrant. So it's just splitting it up into quadrants, basically.
Ferocious Lightning: Okay.
Distinguished Dromedary: And then we're just recursively calling our binary search and then summing up all the counts.
Ferocious Lightning: Okay.
Distinguished Dromedary: Okay, and then I guess here, For time and space complexity. So space complexity, that's easy. That is just— well, actually, we would have to keep track of our recursive call stack, which I think at any one point— so let's try an example. So here we're breaking it up into 4 quadrants. And then again, we're breaking it up into smaller quadrants. But really, I think as far— we can only really go as many black holes as there are. In a single recursive call.
Ferocious Lightning: Yeah.
Distinguished Dromedary: So for here, I think it's just going to be the space is just going to be a number of black holes, so our count. And then the time complexity, so binary search is log n. To find the small value. And then we're doing it for, I guess, the number of times there are black holes. So if you consider m to be the number of black holes, and then again, like, if you consider— Sorry. I guess n to be the cells, it would be m log n.
Ferocious Lightning: Okay, do you mind writing it down?
Distinguished Dromedary: Sure, so time complexity m log n, and then space complexity, this is just our recursive calls, so it would be, O of M, so M being count of black holes, and then N being the number of cells.
Ferocious Lightning: Yeah, line 46, the space complexity. Are we sure it's bounded by the number of black holes?
Distinguished Dromedary: So let's try it with an example here.
Ferocious Lightning: Yes.
Distinguished Dromedary: So with our example here, we put in 0, 9, it returns true. Then we split this up into 4 roughly equal squares. And so we run binary search again here. It returns true. And then we split this up again into 4 roughly equal squares. And so this will return true, so we split this up again into roughly equal squares. So we will— so for every time we're running our recursive call, we're essentially creating 4 squares and then just going deeper and deeper and deeper. I mean, in theory, that like, if there's only one black hole, 3 of them should return immediately, and then one of them should return, or should just keep on going. So I mean, I think. Could that be 4? I mean, so at every—
Ferocious Lightning: Go ahead, I'm sorry.
Distinguished Dromedary: Yeah, I mean, maybe like if at every point like we're making 4, could it be 4 to the m?
Ferocious Lightning: Hello?
Distinguished Dromedary: Yeah, can you hear me?
Ferocious Lightning: Now I can hear. It's just that it disconnects every so often. Let's do something. Let's follow up with this a little bit later so we can keep moving on.
Distinguished Dromedary: Okay.
Ferocious Lightning: But we can use this as a baseline. Okay, continue.
Distinguished Dromedary: Okay, yeah. So yeah, do you want me to start trying to code this up?
Ferocious Lightning: Sure, go ahead.
Distinguished Dromedary: Okay. So def count_blackholes. So this takes in— I guess we agreed upon a bottom. So the inputs are bottom x. Bottom y, top x, and then top y.
Ferocious Lightning: Okay.
Distinguished Dromedary: And so now we have to define basically a recursive binary search function. Um, the def binary search, um, or do we need to define a recursive binary search or could we just use the initial as our recursive function? I think we can just use our initial because this is going to be the same inputs.
Ferocious Lightning: Uh-huh.
Distinguished Dromedary: So if, um, let's— so what is our helper function to devise that black hole presence?
Ferocious Lightning: Yeah.
Distinguished Dromedary: And then—
Ferocious Lightning: You can just say that— you can just say that within the context you're being provided is black hole present. Let's assume you're importing that from some module or something. So— or however, it's present in the context just to make it simpler.
Distinguished Dromedary: Okay, so device.blackhole present.
Ferocious Lightning: Or you can just put black hole present. It's fine.
Distinguished Dromedary: Okay. So if black hole present, so should I pass in tuples here? Should I just pass in all 4 coordinates? Or like an array?
Ferocious Lightning: What does the— sorry, what is the problem statement?
Distinguished Dromedary: It says bottom left, top right. I'm not sure, like, should the bottom left be a tuple?
Ferocious Lightning: Okay, yeah, let's assume you're passing tuples. So we can use that data structure to pass the coordinate tuples.
Distinguished Dromedary: The bottom, bottom left, bottom right. So this is the bottom left of it, so bottom X, bottom Y, and then top right. So a tuple of top X, and then top y. So if black hole present— so actually, let me actually just do if not black hole present, return 0. So this is easy, our base case. If there's no black hole present in the entire grid, we don't have to do anything.
Ferocious Lightning: Okay.
Distinguished Dromedary: And then second is If— so what if our tuples equal each other? So if our tuples equal each other and we've already checked that there is a black hole present, then we return 1. So those are our two base cases here for our binary search. And now basically what we have to do is what we described is just basically breaking this up into 4 quadrants. So let's— yeah, this is— this can have a lot of— there's a lot of edge cases here. So let's get our middle— so our middle X, and then our middle y. We might need more, but let me just try with this. So our middle x is going to be— so bottom x plus top x divided by 2, and then our middle y, so that is going to be bottom y Plus topY divided by 2. Okay. And now basically let's try defining our 4 parts now. So let's start with the top.— so let's start with the bottom left quadrant. The bottom left quadrant, so count black holes. So for this, we are starting at our bottom x— Uh— Bottom y, and then where are we going to? We are going to our middle x and our middle y, which would be the top coordinates of our bottom left quadrant. And then now let's do the bottom right quadrant.
Ferocious Lightning: Okay.
Distinguished Dromedary: So counts black holes. So now, okay, going back to our example, our example 1, we need to start at, we need to start at, bottom x 1. And also just as a point of clarification, I'm not sure if our function will need it, but what would happen if I pass in a value to black hole present that is out of bounds, or do we want to just try to avoid that as much as possible.
Ferocious Lightning: Let's try to avoid that. Actually, let's avoid that, yeah.
Distinguished Dromedary: Okay. So we might—
Ferocious Lightning: I mean, you could— sorry, to give you some— maybe you could, you know, have it assume that it throws and then capture it, but it's gonna make things more complicated. Let's just write it in a way that you don't pass something that's out of bounds.
Distinguished Dromedary: Okay. So yeah, let me actually circle back to that at the end and just—
Ferocious Lightning: Yes.
Distinguished Dromedary: I think that I would just keep that in mind that we want to avoid that. So bottom x plus 1, and then what should be our Y coordinate? I think it should just be bottom— no, this should be middleX plus 1. Yeah, middleX plus 1, and then this should be our bottom y. And then where are we going to? We are going to middle x and middle y. So let me just verify that with our example above. So That would be our second recursive call, so bottom, bottom x plus 1. And so middle, middle x plus 1 would be 5. And then we are just copying over our bottom right. And then we're going all the way up to— so that would be, yes, we're doing bottom, so this is the third one. Wait, why are we going up? Yeah, 9, 5. Yes, and we would be going up to— oh, we actually want to go up to the end. We do not want to go up to the middle. It's a good thing I checked that. So we want to go up to top x. Here. So we're going from the middle, middle x plus 1 to top x. And bottom y to middle y. Yeah, that makes sense. Because we're essentially taking the other half of that x quadrant. And then, so now let's do top, top left quadrant. Here. Top left quadrant, count black holes here. So where do we want to start? So we have our middle X and middle Y. And we want to do the top— actually, the top right quadrant, let's do first. So the top right quadrant, we want to start with middle X plus 1 and middle Y plus 1. And then we are essentially just going to our top X and top Y. So top X, top Y. And then here we are doing the top left quadrant. So counts, black holes, um, and then for here, we— the x value we want to start with is our bottom x. And then we want to— our y value should be the middle y plus 1. And then the x here should be— we're going up to the middle x. Um. And then the top y. And so now we have defined basically our two— our four quadrants. And we essentially just want to return the sum of these. So bottom left quadrant plus bottom right plus top right plus top left. And then this should be basically our, um, function that's recursively calling. Yeah, this is the find_and_search function here. And then yeah, we wanted to circle back to see if any of our bounds would ever go over. So here. I guess we can just put in some calls. So if, just as guardrails, so if middle x plus 1 is greater than, is less than or equal to top x. Else, make this 0, and then yeah, we can just keep adding here. So middle x plus 1. Less than or equal to top x and middle y plus 1 less than or equal to top y. Else, uh, we can just— Okay. Define that as 0. And then here again, if middle y 1 less than or equal to top y, else assign this a value of 0. Okay. And yeah, I think this is our entire function.
Ferocious Lightning: Okay. Can you hear me?
Distinguished Dromedary: Yeah, I can hear you.
Ferocious Lightning: Oh, because there was silence there.
Distinguished Dromedary: Okay. Yeah, yeah. So yeah, I think this is our entire function. I'm not sure if you wanted to revisit the space complexity we talked about earlier.
Ferocious Lightning: How can we verify if this works or not? Could you be a little bit more—
Distinguished Dromedary: Oh, you want me to run through some examples? You want me to run through some examples?
Ferocious Lightning: Let's try running it, please, yes.
Distinguished Dromedary: Okay. But yeah, let me try to find like a small example here. So what I'll do is I'll just copy over. So at the bottom here, just copy this over and delete the— So we're running through a small example and I'll put in, I guess, two values here. Yeah, so we essentially, we start with, so we're given 0, 0 and 3, 3 as our inputs. Our binary search starts. Starts, or our function starts, it checks is black hole present within this entire grid. If we get a return value of true, so we know there is at least one. And then we split this up into essentially four quadrants basically.
Ferocious Lightning: Mm-hmm.
Distinguished Dromedary: And run, recursively run binary search. So our middle value, our middle x here will be 1, 1. And so we create essentially 4 subcells. And let me try to not mess this up here. So 0, 0, so this is the bottom left, goes up to 1, 1. And then we go from middle x plus 1, so that will be 2, 0, up to— So then again, our— this is bottom left, and then this is going to be bottom right. So 20 up until 31, and then now let's do at the top right. So this will be— so we are doing middle x plus 1, so we're starting at 2. Plug in here, so middle x plus 1, y plus 1, so we're starting at 2, 2. And then we are going until basically the top, so 3, 3. And then this will be our top right. And then, yeah, I— again, for the sake of time, I won't, like, finish this off, but, like, yeah, let's— we're doing the top left as well. Which would be 2, 2, 0 up until, yeah, like 1, 1, 3. And so like, yeah, we're basically going to call binary search on our bottom left. We're going to return true. And then we're going to recursively run this again, splitting it up into 4. 4. Bottom right gets a return value of false, so we just return 0. Bottom— so top right gets true. We recursively run it again. That'll break it up into 4, and then we'll get one of these being 2, 3, which will return 1. And then top left, we get a return value of 0 from our helper function, so that returns 0. Okay. And then we will— again, the recursive stack will pop up, and then we'll get a 1 from our bottom left quadrant and a 1 from our top right quadrant. We'll sum those up, and we'll return 2.
Ferocious Lightning: Okay. All right. Anything else you want to test?
Distinguished Dromedary: Let me think about if there's any edge cases here. So if our matrix is empty, it'll just return 0 because our wrapper function gets that. And then I guess, I guess what if What if our matrix only has like one, is just vertical or just horizontal? So it only has like one column or one row. But I think in that case we should be fine because we implemented these checks here. So if we're doing middle x plus 1 and middle y plus 1, it'll just give us 0. For those values if they go out of bounds. So we're never going past that. And then if we ever have a case where our matrix is just one point, we will basically just hit the base cases here. So it'll return zero if a black hole is present. Otherwise, it'll return one because our values are equal. So those are the edge cases I can think of. Okay.
Ferocious Lightning: Okay, cool. All right, great. We are about time here. So let's go on to feedback. That's okay?
Distinguished Dromedary: Okay.
Ferocious Lightning: Okay, great. So how do you think you did?
Distinguished Dromedary: I think I did decently well. It was a little bit of a tricky problem. I think that I could tell it was a binary search problem. I obviously got tripped up at the space complexity. So that's something I probably want to review. But I think I was able to get to an optimal solution. Again, the edge cases kind of threw me off in making sure that we have the right coordinates, and then the space complexity was— yeah, I got tripped up there that I probably should have done better at. But I think I did well communicating, in my opinion, and getting to an optimal solution.
Ferocious Lightning: OK, cool. Let me give you my feedback and see where we align, okay? All right. So hold on a second. Just a second. Okay. So let's talk about communication. I think you did very well with communication. So your assessment in that regard is correct. Give me a second. Some things I think you should improve based on this session. So at all times, I understood what your thought process was. You asked a lot of clarifying questions, which is great. You asked about constraints. You asked about some edge cases. You took the time to, you know, figure out how the function signature would be. The only thing I'd say is that at some point, it kind of had to— get you back to reading the problem, because even though you were proposing that you should return a list of coordinates, the problem is not asking that. That could be fine, but it was asking for a count. And granted, this problem is a little bit extensive on purpose. It kind of gives a whole story, but the bottom line, like you said and like you figured out, is a quad binary search, right?
Distinguished Dromedary: Mm-hmm.
Ferocious Lightning: So just pay attention to that, 'cause some interviewers might not be as candid and will just, let you out there to try until you figure out that what you got to get is the count. Does that make sense?
Distinguished Dromedary: Yeah, that makes sense. Yeah, I should have, I should have read that part. I was getting tripped up a little bit with that.
Ferocious Lightning: Right. Yeah. And, you know, sometimes, I mean, I gave examples, but in many cases there's not even going to be examples. You have to figure out an example and agree with the interviewer and clarify that this is what you're looking for. But because of the timing issue of this, from this problem is very extensive, I think it works better when I put examples, but just also bear that in mind. I like that you were writing down all your thought process. That to me is very valuable. Also, you proposed the brute force solution from the get-go, so you could use it as a baseline to start optimizing further in time and space complexity. One recommendation, just write— you know, writing is good. Write a little more. Just to say, okay, you can always go back to say, hey, I proposed, I don't know, what I would do is maybe on line 25 you can say, okay, brute force iterate each cell, yada yada, yields big O of n, la la la. So basically it's there, it's written, both you and the interviewer can see it, and then you can say, okay, so based on this I can keep optimizing down. So it kind of reads like a document, if you know what I mean. Right, it's just a small detail, but it helps with the whole communication and also you got it there so it doesn't, you know, you can go back to it. So yeah, that was, other than that I think it was pretty good. Save that in a few, sorry, give me a second. I like it that you proactively offered the time and space complexity. That's important from the get-go because you're again saying, okay, this solution I'm proposing, this is the performance of it. You're agreeing on a common accepted measure of performance for the algorithm, and then you're justifying why you need to optimize, right? Because you're saying I'm going from a big O of n to a logarithmic time complexity. So that's great. I didn't have to ask you for it. You gave it proactively. And yes, like you said, just— Be careful with the space complexity. The space complexity of this one is generally agreed to be the size of the stack. So you don't have to be worrying about the number of black holes. It's basically how many recursive calls you have to do, and it'll be the size of the stack. But make sure that when you explain time and space, it's thoroughly explained like you did with time and with space. Like, not just saying, "Oh, it's just the size of the stack." It's the size of the stack because of all of this. Does that make sense?
Distinguished Dromedary: Yeah, that makes sense.
Ferocious Lightning: Perfect. Okay. You properly asked for the constraints. So all of that as far as communication is great. Let's go to problem solving. So give me a second here. I'm looking at my notes here. So yeah, the problem solving, I think you did an excellent job. You basically said, okay, again, going back to the brute force, it's a big O of N, and then the next, logical, one of the things one could think of an optimization is binary search. You properly mapped this to a binary search problem. And actually what I loved about this is that you first said, okay, if it's binary search, the first thing is to split the ranges in two. But when you started visualizing and it says, oh no, wait a minute, actually I have to split this in four. And getting that insight into that problem is what basically smoothes out the rest of the problem. If you don't get to that insight in time, this problem is going to drag on forever until you get to a starting point. So the fact that you got to that insight very early on, I think it was at the— oh, I got my notes here. Yeah, basically at 2:15, like 15 minutes into the interview, which is great timing. You told me in the beginning that you were a little concerned about timing. So I can tell you that you did great with timing. You set yourself up for success on that one when you got that insight, okay? Only thing is at some point I had to ask you to review those coordinates. You got a little dizzy with that. It's just a minor detail, but anyway, you took that feedback properly. You reviewed the coordinates and then you said, "Oh, okay, now I have to put this here." Yeah. And that there and that there. Makes sense so far?
Distinguished Dromedary: Yeah, it makes sense.
Ferocious Lightning: Perfect, great. Okay, and then you properly, at 21 minutes into the interview, you propose the base cases for your recursive function, which is also great. Not sure if you wrote it down, but I would recommend you to also write it down at some point so that we, so that the interviewer can reference whatever your thought process was. It's just a minor detail, but it could help, you know, even if you could just do a very concise pseudocode or outline of what you were thinking, like whatever, there's the base case is yada yada, you know, and so and so. So it's kind of a skeleton that you have out there. That's very helpful. Right? It kind of makes— shows that you're making an extra effort to properly communicate what your strategy is, if that makes sense. So yeah, that's a recommendation I have. Other than that, you got the right approach, the right algorithm. Sorry, I'm looking at my notes here. Great. Okay. Then you asked the magic question, "Should I go ahead and code it?" Once you got the sense that you and the interviewer were in agreement of the strategy. Which is also great. And then I gave you the okay to code because I understood your strategy and say, okay, we're good to go with this. I'm satisfied.
Distinguished Dromedary: Okay.
Ferocious Lightning: So as far as coding, I see well-structured, extensible, and properly formatted Pythonic code. I can read everything properly well. So no complaints about that. Maybe just a small caveat. You did ask about the edge cases and some limitations. Maybe if you wanted to make it even better, you could wrap this into another function that validates the input parameters and raises an exception. It just takes 20 seconds to do that, but it gives you a lot of points. See what I mean? So instead of going straight into the signature of— into the function, You could have gone into, like, nest this into a parent function that would validate these inputs, just an extra thing. Right?
Distinguished Dromedary: Okay. Yeah.
Ferocious Lightning: It's just a good thing to do. You know, like, basically, if I give you a string or if I give you something that's out of bounds, you raise an exception. It takes 2 seconds and it looks very good. But just a small detail. All right. The code is correct. Uh, you— the only thing I would tell you is that I had to kind of prompt you for the dry running. And like, when at the 2— sorry, where is that? 2:50-ish, 2:40— no, 2:46, uh, or 2:44, uh, which is kind of almost at the end of the interview, uh, you said, okay, so this is the algorithm. And then I kind of said, say, okay, do you wanna validate if this looks good? And so, oh, you want me to, you should proactively say that, okay, the way this should pan out is this is my algorithm, this is my solution. Now let me validate that this actually works. Let me validate that what I wrote actually works. So I'm gonna dry run it, right? You should do that proactively always, always, always. And you know, start with a small use case and then go into a more into a bigger one. And when you're dry running, I would recommend not only talk and change these numbers, which is good, but try to see if you could go, you know, connect it more with the code, or at least, you know, put— some people use a style in which they put a comment here, and then they put the value of the variables there, and they go line by line as if they were a debugger in IDE. Or other people just put the— values of the variable here, but they draw the whole progression of the variables, right? And they go back and forth with the code. If you are more thorough with this, I guarantee you're gonna find bugs. There's always bugs, okay? I don't see any bugs in this one, so great. But you could, especially I kind of know that [REDACTED] is very picky about finding those bugs and that syntax, and that could take you, take points out. So beware of those things. All right, but other than that, I would say that you did great with the code. This code works. It's verified, and yeah, it's a complete solution, which is what I would be looking for as an interviewer. That works. So based on all of that, my verdict would be that I would be inclined to hire you.
Distinguished Dromedary: Okay.
Ferocious Lightning: As part of my feedback. Does all this make sense?
Distinguished Dromedary: Yeah, that makes sense. I know [REDACTED] has their own scoring tiers. Is there any particular tier you'd put this in?
Ferocious Lightning: Well, I don't— I'm familiar with the process, with [REDACTED] process, not entirely familiar because I never worked at [REDACTED]. I do work at another big tech company. We have similar graduations there. In my case, if I were to judge, I would be between inclined and strongly inclined. Okay? If the bar is very high, you would get inclined rather than strongly inclined, because of all the little nuances I gave you.
Distinguished Dromedary: Okay.
Ferocious Lightning: You have to think about it. They're interviewing a lot of people. They have a very high bar. So they're expecting all these things. Still, inclined to hire is, in my opinion, a very good score. And then depending on how they do with the other interviews or whatever heuristic they do to gauge a candidate, that counts towards your point. But definitely to me, this is a higher, higher towards strong and higher, if that makes sense.
Distinguished Dromedary: Okay, that makes sense. Yeah, thank you so much.
Ferocious Lightning: No worries. Any other questions?
Distinguished Dromedary: No, nothing, nothing else for me. I know we're kind of like overtime, so I don't want to keep you too long.
Ferocious Lightning: No, it's okay. I have 2 more minutes if you want. I'm good. Otherwise, it's whatever you want, yeah.
Distinguished Dromedary: Yeah, let me think here. Do you have any tips on like if I'm struggling with like the time and space complexity? Yeah, 'cause I hear, I'm not even sure. Like if there is like a call stack, do I have to I guess, try to calculate that out like I tried to do for this problem? Or can I just say O(n), O(n), n being the call stack? Because I feel like an interviewer might push me further, like how big could the call stack get?
Ferocious Lightning: Well, that's a good question. I mean, you mentioned time management. I would timebox it. Like if you're struggling a little bit with this thing, you could say, look, I think this is based on the call stack. My intuition is that a call stack would look like this. You can even draw it out and say, but I'm not sure about X, Y, and Z. And then maybe the interviewer might most probably say, okay, look, we can review this later and we move on. So you kind of have a good idea, but you're not eating too much of your precious time into that. Other people might say it differently, but anyway, to be able to overcome that, you just get a few problems that have complicated branching or have, you know, this kind of tree recursive or dynamic programming and break down how you would calculate the time and space complexity, right? Yeah. If that makes sense, and use it in practice. Does that help?
Distinguished Dromedary: Yeah, that helps.
Ferocious Lightning: Okay, yeah, no, okay, go ahead, any other questions?
Distinguished Dromedary: No, nothing else for me.
Ferocious Lightning: Okay.
Distinguished Dromedary: Yeah, I'm popping.
Ferocious Lightning: All right, great, best of luck and thank you.
Distinguished Dromedary: Yeah, thank you so much, see you.
Ferocious Lightning: Bye.
Distinguished Dromedary: Bye.