Interview Transcript
Effulgent Covariate: Yeah. So mainly my focus has been working my way through the. Oh, sorry. I said it was like, reconnect to yours. I was spending most of my time doing the. Working through the neat code 150. And. Yeah, the most of the problems I get after working through them, there's some that, like, there's. There's one that I'm working through now that's kind of confusing me. At least the optimal solution, it's. Oh, but it's funny. You know how you, you know how you said the. There was this problem with like, median of a data stream?
Stochastic Panda: Oh, right.
Effulgent Covariate: That was. Yeah. So actually what was interesting was I found that problem a lot easier to understand than the other median problem with that because, well, I mean. Well, I probably couldn't derive the solution on my own, but once I understood. So there was like a two heap solution, like, it wasn't that hard to implement once I knew the approach to have like a min heaven, a max heap. So. So that's good. But, yeah, so there are a couple that I was working through, but would. So today, would we want to do a coding question or would you want to go over the questions I had? I'm not sure which you think would be more useful, but, yeah, I think.
Stochastic Panda: A bit of both would be great. You know, as always.
Effulgent Covariate: Yeah.
Stochastic Panda: My goal is to help you. And from my session notes I did have that we could focus on a bit of additional level setting and feedback for code. But as always, I think it's always good to start with some updates. You've provided some good updates on how you've been going through the NEET code 150. Any other updates with respect to, like, interviews or top of mind?
Effulgent Covariate: No. So I haven't had any interviews yet. I'm just kind of building my skills and everything. And I have so I've been listening a lot to Ethan Evans, and the YouTube videos are really helpful, or they seem to provide good advice for general workplace things. And that's been interesting because it's easy to listen to while doing other things. So I've been doing that, and I have things on my to do list. Like there's like the Facebook ML thing. I just haven't gotten to that yet, but so I'm doing what I can do it as much as. But this, between last time and this time, I really tried to hone in on working through more coding problems. Like, and what's the word that was used? I don't remember where I heard it, but it's like, don't bring a knife to a gunfight for interviews. So I know where I see these problems. And, you know, it does get easier as I go. Some of the problems are still hard, but I think it's sort of like building a muscle, which is good. So.
Stochastic Panda: Excellent. Yeah, I think that's great that while we level just a few things and develop focus areas. Yeah. In the meantime, if you can focus on those things, but also practice and go through things like the Ethan Evans videos, those are great. And also some of the Facebook machine learning, like field guide. And I don't know if I also recommended for ML system design the book by Alex Shu. And what's.
Effulgent Covariate: Oh, does he have one about ML? Or is there. Or is that general? Oh, okay.
Stochastic Panda: Yeah. So let me add that, and I'll be sure to write it as well. But I don't forget I did see.
Effulgent Covariate: That because I'm part of byte. Byte. Go. Now, which, like, since it sends out, you know, I think it sends out like two or three things a week, which. Which is good to, like, keep me non rusty on those things. But I think there's something on that site that lists ML system designs. I wonder if that's based on the book, too. But either way, it's good to have everything that I can, so.
Stochastic Panda: Absolutely.
Effulgent Covariate: Yeah.
Stochastic Panda: And my experience on their website is there's pretty good overlap, actually, between the paperback ML system design interview book. So either one is good, and it's really good to practice because they go into a lot of back of envelope calculations that influence the design. So that's always helpful, too. Cool. Okay. Before we get started on code, any other questions or updates?
Effulgent Covariate: No questions. That would take less than 15 minutes, probably, to go over, so I'll hold off for now.
Stochastic Panda: Okay, cool. In that case, let's go over one of the problems I have for today.
Effulgent Covariate: Okay.
Stochastic Panda: And. Yeah. And we can get started. So I'll paste it in. Let's see here at the top, starting around line eight.
Effulgent Covariate: Okay. Ah, all right, I see. Okay, so given n by n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return a clear path is a path from the top left cell to the bottom right cell. Okay. Such that all the visited cells of the path are zero. All the adjacent cells are eight directionally connected. That is, they're different and they share an edge or corner. All right, so let me think about this. So, 123450. I see. Okay. So I get what eight directional means. Okay, so eight directionally connected. And the length of a clear path is the number of visited cells. I see. Okay. So actually give some examples. So if we look at example one. So we started this zero. And if we want to go from here to the bottom right, then we start here, we can go to the right twice and down twice, which makes the length four, because we want to only pass zeros. And if we encounter a one, that's illegal. I understand that example. And then this example down here. So this, let's see. So there's no output. But if I reason through it, then let's see this one. We actually, is it even possible on this one? It looks like it's not. So if we try to go down, we're trapped. Try to go down and right, we're trapped. And it doesn't say anything about being able to like wrap around. Like, we go off to the left, it won't go back to the right. So I believe we're trapped on that example. Is that correct?
Stochastic Panda: Yeah, exactly. That's right. So that indicates that where we would output minus one.
Effulgent Covariate: Yeah. So anyway, so if I'm like just thinking about this problem. So the idea is all of the adjacent neighbors, whether it be right, left, up, down or diagonals, which, you know, which there are calculations for those. But, but I think the idea of this problem will be to implement some sort of breadth first search, because that that makes sense for doing things with neighbors. And that could be implemented by using like a queue. So let me just think through how we can apply that here. So it's like we start at, let's say we look at the example where it works. So we start at this zero, we'll get its neighbors, and then for any neighbor that's a one, we just stop breadth first searching that particular path. But if it's a zero, then we can recursively breadth first search recursively or iteratively, breadth first search a path with a zero, and then we can keep doing that until, well, so let's see. So let me think about first the case where, let's think about a case where we get stuck. So how do we know that? How do we know that we're stuck? So we know that we're stuck if we, oh, I think so. We're stuck if we empty the queue of breadth first search but haven't gotten to the bottom right. Or at least that's my thought right now maybe as I flesh this out more, it'll change. But that's my first thought. Then, of course, the other way, it would just continue at the queue. But then if we get to the bottom right and it's a zero, then, you know, then we've won. So in terms of the shortest, okay, so that covers, you know, getting stuck versus being able to clear it. But now the question is how do we get the length of the shortest? So, you know, there could be many different paths. And through breadth first search, so how can we keep track of, so if we start from the upper left, and so if we do things adjacent to that. So in our recursive function, we would have to keep a parameter for, I guess, like, which, you know, like whether we're on, you know, whether we have one level of neighbors, two level of neighbors, so on and so forth. So that when we get to the end, it will tell us. And then, so wait. Oh, so returns an integer. So with the length. Okay, so we don't actually need the path itself, we just need the length of the shortest. And actually, I think, and this may flesh out on the implementation, but I think breadth first search, I think it gets to you the shortest on its own, if I recall. But I don't remember the proof for that. But I'm pretty sure that just by implementing breadth first search, I think that alone will return the shortest. Okay. All right. So anyway, so I think I have enough of the design to start some code here. So let's make a, okay, so our main function. So it'll take in, let's call it shortest clear path, and it will return an int for the length and, you know, return negative one if it's bad. So return an int. It'll take in, so it'll take in a, so two dimensional grid. So that will, so in Java that could just be, I guess, a double int array.
Stochastic Panda: Exactly.
Effulgent Covariate: For grid. Okay, so there are a couple little coding things that I'll have to think about here. So getting the neighbors. Right. So. Well, so let's see. So you've taken the grid. Is there anything else we have to take in off the bat? I don't think so. Okay, so, all right, so what we'll do is, okay, so we're going to need a helper function too. So let's call it bfs. And I think, I mean, I'll have to see what it will return, but maybe that will also return an int. But it'll have to take in the grid. It'll have to take in. So the level that it's on. So like, you know, if we're, if we're at like the neighbor, the upper left or the neighbor of its neighbor and so on and so forth. Okay. Is there anything else? I think that might be good for now.
Stochastic Panda: Okay, and let me ask a brief question here. So I think there is a way to implement bfs with recursion, right. So that if you're thinking about maybe repeatedly calling your helper method bfs, I think there's a way, but I think you mentioned. Right. And we can go that way, but yeah, if you're thinking of with a queue. Right.
Effulgent Covariate: Yes.
Stochastic Panda: The minor hint I'll provide or two minor hints is one. Right. We want to initialize our queue at a special place, and while the queue is not empty, we can do something basically iteratively.
Effulgent Covariate: Yes. Yeah, and yeah, I've seen code like that too. So that is, yeah, I mean, I don't know, I even put. Yeah, so I guess, yeah, DF's is usually the recur, the recursive one. So. Okay, so here we make a queue. Okay, so what will this queue actually hold? So we want to queue the, well, probably the coordinate would be the most helpful because, you know, zeros and ones are all over the place. So the distinguishing factor is where it's located. So let us do single int array equals new linked list. Okay. So we're going to start it at. Well, okay, well, so a couple things can we have. I mean, I assume we could be passed in an empty grid, right? I mean, that's an easy case to cover, so I can just do it. So if grid length equals zero. Oh, well, actually that's a good question to ask. So what do we want to do if it's empty? Is that considered no clear path or.
Stochastic Panda: Yeah, that's a great question. So let's briefly cover pros and cons of returning minus one versus returning some exception. Which of those two do you think might be better in like a production environment?
Effulgent Covariate: Well, so I'm just thinking, so in the context of the problem, I mean, so it has to tell us whether there's a path. So if we have an empty grid, I mean, I don't see a harm in returning negative one because, like, we didn't get past anything. I mean, it depends what the caller would want to do with it. So I don't think necessarily us throwing an exception off the bat is necessary. But, I mean, I could go either. Like, if you had a weapon to my head, I'd probably say I'd probably just return minus one. But if you think there's a better option, I could do that. Yeah.
Stochastic Panda: And minus one also makes sense if we are almost pedantic, if you will, and say a clear path is only when there's a zero in top left and a zero at the bottom right that we can get to right. So if it's an empty grid, there's no zeros. And so minus one makes sense. Okay, cool.
Effulgent Covariate: Okay. All right, so we got that out of the way. And so another, like, coding thing. I know it's helpful for these. So we have int, rows equals grid, flank and calls equals grid zero link. I remember that from some practice problems I've done. Okay, so we got that. We have rows and columns. Okay, so now, so what specifically. So I. So basically what we'll be doing. So, like, we start at. Do we just kind of want to loop through. Through this and get neighbors? Well, okay, so another thing we'll have to do is we don't. Let's see. Can we visit something more than once? So if we have. We have this. I mean, we can. So let me think about this. Well, so within a given starting node, you can't, like, so if you're at level zero, then you don't want to visit something more than once. But if, you know, if there's another zero down here, then maybe you could visit that same node again. So you can't have a global visited queue, but maybe within a given place. Okay, so I have a thought. So, I think this is what you're getting at with your hint. So if we start down here, we could say, hue, dot, add new int, zero, zero. So you can start by adding that and then.
Stochastic Panda: Mm hmm.
Effulgent Covariate: Oh, wait, what did I do wrong? Oh, nothing. Okay. All right, so what we want to do. So something about while the queue is not empty. But let me think. If we want to iterate through. Okay, so I think I have an idea. So we have our int I equals zero, I is less than rows, I plus plus. And then for int, j equals zero. J is less than calls j plus plus. So this will be going through all the coordinates. So we started zero. We want to perform breadth first search. So what we want to do here. So while not Q dot is empty. Okay, so you want to get its neighbors. Okay, so that's one coding thing to think about. So. So the left. So the left will be like x minus one, and then right will be x plus one while the set of the second coordinate plus one. And so let us do. All right, so let's see. Oh, so, well, first we need to get the current. So int car chord, Q dot, pole, and then. Okay, so now what was the. There's definitely a strategy to cover this. I think. I think it was. Oh, I think. Okay, I think I might. I think I might remember this. Okay, so. So let's have. Let's have another. Sorry. Let's have a double integer array that tells us how to get neighbors. So neighbors. And actually, this could be global. So I might move it there. But, yeah, so. But for now, let's see. So we want. Well, actually. Wait, wait. So one. One will be. Oh, yeah. Diagonal. Okay, so, yeah, one. Okay, sorry. So 10010. And then we want the minuses. So minus 10. Actually, I feel like I could lubify this, because at the end of the day, so are all. Let's see. Are all negative. Negative 10. One. Negative 101. We don't need to check zero, zero because that's the same coordinate, but for the other ones. So I guess what we can do. Well, so let's see. So how many. So we're looking at eight neighbors. So let's do this first. So let's just make a new. Oh, it's eight. It's eight by two. Okay, so it's eight by two. And let's get this global, because we only need it once here. Okay, so I have that right there. Okay, so how do we want to. So if we loop over. So. Sorry. Is it eight by. Yeah, eight by two. Okay, so to populate that for zero is less than neighbors dot length. So, okay, so you want to populate this, because when I have, like, negative 10, but so we say if I doesn't. If I doesn't equal zero or. Sorry, hold on. Basically, if I and J don't both equal zero, so if not, I equals zero and J equals zero, then we want to populate it. So. So neighbors. IJ. Okay, so it's negative one. Oh, I should. Yeah. Oh, yeah.
Stochastic Panda: On the right. Yeah, I think you're on the right track here. But just in the interest of time, because you did articulate what you want to do here, let me throw in this.
Effulgent Covariate: Ah, okay. Yeah, I should probably have that.
Stochastic Panda: Yeah. Oh, no.
Effulgent Covariate: All good.
Stochastic Panda: So, yeah, let's just assume that goes fine.
Effulgent Covariate: Okay, great. Thank you.
Stochastic Panda: And I might have done something wrong because it doesn't. Oh, yeah. Maybe just this part.
Effulgent Covariate: Just, yeah, thanks. Yeah, perfect. Okay. Thank you very much. All right, cool. Yeah. Okay, so that's that. All right. Thank you. So, okay, so all the queue is empty. Okay, so we got the current coordinate, right? And then, okay, so we get its neighbors by. So let's see if we iterate through this. So, like if we have neighbors, zero, and then we. Okay, I see. So for int, array, neighbor in, neighbors. So, okay, so let's see. Curr, zero plus or, sorry. Plus nb, zero. Let's see. I'm just this kind of pseudocode at the moment. Curricord one plus nb one. Okay, so.
Stochastic Panda: Yeah, so you have like a new x coordinate and a new.
Effulgent Covariate: Yeah, yeah. I'm just silly coding thing, but, okay, so thinking about. So, yeah, because we're going to have, yeah, we're going to have eight of these neighbors. And let's see, I was thinking, well, so we're going to want. So the new coordinates, let's say ker neighbors. So, all right, so current neighbors, zero. Wait, wait, wait. No. So the row will be I ker neighbors. I zero equals currency. Okay, sorry, sorry. It took a while. And then, okay, so current ers. And then current neighbors, I one equals similar thing, but with ones. Oh, okay. Yeah, there we go. Okay. All right, so we have, okay, so the current neighbors are all populated. So what we want to do with that is. Oh, so once we have the neighbors, we want to say we want to queue. Let's see. Do we want to check anything before we queue the neighbor? So we want to say, I guess, I think for now we don't have to. So I think we could just say q. Let's see, q, dot, add, curve. Well, wait, it's a queue of.
Stochastic Panda: Pairs, right?
Effulgent Covariate: Yes, yes, yes. Okay, so it'll be, well, we could do, if we do, is a shortcut, Q. Do not add all current neighbors. I think that will work.
Stochastic Panda: Okay, so let me give a hint here is suppose that we, let me ask this way. Right? So as we're exploring the layers of this queue, you mentioned two important things in the beginning. One is we want to proceed, right. If one of the neighbors satisfies two conditions, right. A new neighbor.
Effulgent Covariate: Oh yes.
Stochastic Panda: You explore.
Effulgent Covariate: Yes. Has to be a zero. Yep. Yeah. So that's sweet. Yes. That's one thing. So it has to be a zero. And it has to.
Stochastic Panda: Yeah.
Effulgent Covariate: So it has to be with, has to be not visited within what we're currently looking at. So I guess within the while loop. Okay, so.
Stochastic Panda: So my hint is before we add everything to the queue, maybe let's check one neighbor to visit or one potential neighbor to visit one at a time. Right. So if we did something like. Right, because we want to be careful about how big our q gets. And so my hint is what can.
Effulgent Covariate: We do with new X and bound checking? So we can, so basically has to be between, well, okay, so X has to be between zero and has to be less than rows. I mean, sorry. Less than calls. And then the Y has to be, okay, so if, well, okay, so if it's out of bounds then what do we want to do? Then we want to just skip, I think. Okay, so if new X is less than zero or new X is greater than, let's say it will be greater than or equal to m. Let me see. I mean, greater than or equal to calls. So it'll be great. Yeah. Greater than or equal to or new Y is less than zero or new Y is greater than or equal to rows. So that's the bounds check. Okay, so if that's true, then I think we'll want to just.
Stochastic Panda: And one more condition. Right. Like what if new x and new Y represent a coordinate in the matrix where we have a one?
Effulgent Covariate: Oh, yes. Oh, also I think, let's see, I have an issue here. So I need to, so we all want it to be within. So because populating the neighbors, I think we want to close it here. Okay. All right, so I'm going to get rid of this right now. Okay. So. Right, right. So if this, then we want to continue. Okay. And, okay, so the other thing we were saying was, and we want to check the value. So if, so you want to go through the neighbors one by one. Oh, so that's why. Well, no, this was just populate. Oh, actually I think I might record zero plus nb zero. Oh, okay. So maybe. Okay, so I think this could be useful to have it. Right. So if, oh, oh, oh, I know what to do. So if grid new x, new Y equals one, then we don't want to queue that up. So. Yep. Well, it's actually. Okay, so it's probably better is. So instead of doing a not, let's do the good condition so if it's zero, then we want to add it to the queue. So q dot add, let's say new int. So this will be the, oh, the new x and new y. Okay, new x, new y. Okay, so let me think. There's any other, okay, so we did bounds checking if it's zero, we want to add it, but, so thinking is there a situation where, because I'm, okay, so this, we're going to queue opposite because of that. Because the situation I'm worried about is if like if we're, let's say we're, let's say our main node is the second zero here, then we're allowed to queue up that third zero like if we started here. So we only need the visited condition. We just need within. So I guess, well, one option is, what I could do is I could, on the next iteration of the while loop I could always clear the visited, whatever data structure. Like a Boolean actually here. Yeah, let's do that. Okay, so let me make a boolean. Well, so hold on a second. It will be, oh, oh, so it'll be a boolean for each coordinate. So that will be right, right. It will be visited. New boolean. Grid dot length. Grid zero, dot length. So we have this visit thing. So what this will have is whether that's been visited. And by default booleans are always false. So that's good. So if we, so before we add it to the queue, we want to say, so if that, and not visited. I'll just copy this. Okay. All right, that's good. Okay. And then we're gonna have to mark it as. So once we add it to the queue, then we're gonna want to say that this is true. So we don't do it again.
Stochastic Panda: Exactly.
Effulgent Covariate: Okay. Okay, so now it's actually, hold on. Okay. All right. So now what we want to do is we want to clear, so if we get to the end of the while loop, we're going to want to clear that visited because when we get to a new node, let me, let me. Well, no, yeah, because, well, okay, so a couple things. There's that visited and then I still haven't implemented the leveling yet. So if we, you know, so if we're at like this, if we started this first over at the second node, that's one away. So we have, need to have some sort of counter too. So I'll put that in, but, okay, but in the meantime. So what we could do is at the end of the while loop or actually at the beginning, we could do at the beginning. So. Yeah, yeah. So at the beginning. Hold on, hold on. Oh, I can just do it up here. So, because we already have an in J, so visited IJ equals false. Okay. Okay. Yeah, yeah, yeah.
Stochastic Panda: So let me offer two more hints. Okay, close.
Effulgent Covariate: Yeah.
Stochastic Panda: So the first hint is on something we mentioned very briefly, though in the beginning is do we need to visit a node more than once?
Effulgent Covariate: Oh, I see. So, well, okay, so if we have, I think the answer is no. I'm trying to reason out how we track that. So, like from the second node we have a third, then we don't really, as long as we know the level relative to. So like, yeah, so we started this second one, we know that this third one is one level away. If we're at this top left, we know that's two levels away. But we would still. Oh, but let's see. Do we even need to necessarily know? I guess. See, does it matter? Maybe it doesn't. Um, yeah, I think I see, see where this is going. So actually, yeah, I think so. I'm not going to bother with this. I'll comment it out in case, I don't think I need to bring it back. Okay, so, so market is visited. Have this. Okay, so now the level. So how do you want to keep track of the level? So basically, once we visit a neighbor and market is visited, we want to, well, no, so it's not a global counter because it's relative to. Oh, hold on, hold on. So, okay, so if we're looking at the immediate neighbors, that's level one, and then, okay, immediate neighbors level. So let's see, maybe is it every time we enter this while loop. Let me think about that. Yeah, so, yeah, yeah, so upper, so upper left. We're queuing up the neighbors, level one. Then we look at, so the next thing in the queue will be a neighborhood, then that will be level two. Okay, yeah, that's nice and simple. Okay, so int level zero and then level plus, plus. Okay, so what we want to do with that is. So basically, so when we go through this, let's see, am I, oh, wait. Oh yeah. So I did my qdot polls. I remove it. So once this is empty, return level. Let's see. I mean, let's see. So I may need to clean up some of this code, but I think the approach is pretty solid. Okay, so let me just, let me run through what I have. So, so we have our visited, we have our queue. The grid is empty. Return. Oh, okay. So I need to cover. So if the path isn't found. Okay. Yeah. So I haven't covered that yet.
Stochastic Panda: Right.
Effulgent Covariate: So if. So, okay. So. Right. So how do we know if we get stuck? So if the. Oh, if the. Hold on. So if visited. If the bottom right hasn't been visited and the queue is empty, then we're stuck.
Stochastic Panda: Mm hmm.
Effulgent Covariate: Yep. So, okay. So what we want to do is if. Let's see. Okay. If not visited. So this will be. Yeah. So it'll just be rows minus one calls minus one. Rows minus one. Minus one calls minus one. Then return negative one. Yep. And then. Otherwise, it's fine. We've cleared. Okay, so that's good. All right, so let me. Okay, now let me resume running through. So we have our rows and columns, the neighbors, which. Thank you for that. So you have. Our level starts at zero. So we start by adding zero. Zero. Oh, okay. Yeah. One little thing I did not do is. I need to say or actually, hold on. So I need. I need a mark. I need a mark. I need a mark. Zero is visited. So let me just do that. Zero zero equals true. Okay. All right. So get rid of this. Okay, so the queue is not empty. Increment the level. Well, so actually, wait a second. This. This is. This won't quite work because. Let's see. So let's say we're at the first neighbor. We increment the level is level one, and then we get to the second neighbor. Oh, no, boy. Oh, but, yeah, but it's queuing up its immediate neighbors. But then. Then we have to bring the level back. Oh, no. But it's only visited once, so this isn't quite. Hmm. Because. Yeah, yeah, yeah. So I see. I see an issue here because this is just literally, literally everything that comes out of the queue, it's incrementing the level. That's not quite what I want. Because I want all the immediate neighbors have level one. Non, you know, have level two. So it's close. I just need to think about how to count for that.
Stochastic Panda: Right. So. Hmm. Okay, so we are at the 40 minutes mark of this problem, roughly speaking. Yeah, I think it's a good stopping point.
Effulgent Covariate: Okay.
Stochastic Panda: And so let me start. Well, traditionally, if you're comfortable with it, let me ask you if in a minute or two, you might describe how you felt about this problem.
Effulgent Covariate: I felt like if I. I felt like if I got to the graphing section of the practice, I probably would have done a lot better on this. I just haven't gotten there yet. Okay. But I mean, the problem seems in line with you know, with what I would expect for a BFS problem, I just haven't really practiced that kind of problems. I didn't know the neighbors array and stuff like that, or I didn't remember how to do that. But, but overall, like, I felt, I felt like I knew the approach there. Just some aspects of coding it up that confused me in the moment, so.
Stochastic Panda: Mm hmm. Yeah. Oh, sorry, go ahead. If I interrupt.
Effulgent Covariate: No, no, that's, that's, that's pretty much it. Cool. Yeah.
Stochastic Panda: So by and large, I would agree, like, the two pieces of good news, if you will, that I would say one is compared with last time. I feel your intuition for finding an algorithm that will solve the problem is a lot better and faster. This problem is also tricky. I mean, the graph setup is a little given to you, if you will, but it is non trivial, at least in my opinion, to say, okay, do I want to do this? BFS, DF's, you can actually do it both. But to really articulate why, you might want to choose one of those. And I think you did a really good job there, especially in the beginning, you said, hey, let me consider both. And yeah, I think DF's will be good because I can go through layer by layer, so to speak. So that was a really positive and also good news in general, I would say, is it's also informative that you mentioned you haven't gotten to the NEET code graph section. Because I think with this problem as a baseline, once you get to that section, I think two things will happen. One, you'll realize that your intuition is quite good and it's just some of the finer points that those practice problems. And maybe one or two more sessions will help with. So that's really good news, right? Like if you had said, oh yeah, I went through all of the graphs on neat code 150, and I'm still getting that's okay too, but you have like a head start there, so that's great. Also, what I really liked is your clarifying questions. Right? Like, what does it mean to be eight directional? And you did a really good job there. You said, basically, I'm going to assume it means diagonals up, left, right, down, and got buy in for that. So that was great. And also you considered the edge case, like, what if this thing is empty? Should we return minus one? Also, the overall syntax that you're using is quite good. Like, it's pretty obvious, right? Like you know how to manage and work with queues in Java. So that, that is all plus signs there. And overall like your solution strategy, I would say the building blocks are there, which is great. Now in terms of the potential areas of improvement, I like to call them is just a little bit more practice with BFS. And maybe looking at the videos too from NEET code will help you gain intuition on what actually are the layers that I'm exploring in this setup. Because once you get the intuition then basically you'll notice that a good idea is within the while loop. Right? Before you do neighbors, you'll want to do something like, how should I call it? Let's say oops, my scrolling 1 second. Yeah, something like queue size is. Or if you want layer size, right, is.
Effulgent Covariate: Q.
Stochastic Panda: Sorry, what were we calling it? Yeah, just q size. And now once you have that layer size then you'll gain intuition and say okay, I want to update my answer. This means that thing is not empty. I'm going to keep adding or traversing this level, but now comes the traversal part. So for the traversal part, here's where you do something like int I zero while I is less than layer size and I plus plus. And that's when you would start right after you do this because you're indicating I know the size of my now I'm going to explore neighbors. And so that's one thing. And also, if you ever feel like you're running short on time, just do a little check on what's the time and space. Because I think if you consider time and space, you've got basically, so to speak, three nested for loops, right? You've got your for loop on line 74, 75 and 76. So when you start seeing something that's quadratic for graph generally, that's okay. There's like a quadratic number of things that touch or number of nodes.
Effulgent Covariate: Yeah.
Stochastic Panda: But this while loop starts getting us into the potentially cubic case, right? So once you start thinking like ooh, I might start getting cubic, then I think you would have seen that actually you don't need these for loops on the coordinates. And I don't know if it'll let me tab over, but basically that's like the pattern of BFF is I have my while queue, I have my for loop for layers. And within each layer I am going to explore and make a condition as to whether I want to add or not.
Effulgent Covariate: I see, yeah.
Stochastic Panda: Right. Yeah. So technically in the while loop we do have two or a nested for loop, if you will. We'll have this for loop on line 81. And we'll also have within inside of it. This is going to be ugly, but I'll just do it a for loop inside. The tricky part here is to think like what's going to be the time and space. Well, it's actually going to be constant time inside of this for loop because the number of directions is fixed.
Effulgent Covariate: Okay.
Stochastic Panda: And yeah, the main cost is really in this top while loop. Why is that? Because the maximal size a Q can be is everything. Right. We just end up touching everything. But we also do two short circuits. One short circuit is here, right on line 94 is I don't want to grow my current layer. The name I'm considering is already visited and satisfies these conditions. The other short circuit and something that will come with pattern recognition and queues is what's my terminating condition? And so for that actually you can put a terminating condition at the top. So you pull it here. Okay, good. And now what we want to do is to say what can I say about determining a condition and my current coordinate? Well, before I even explore the terminating condition. Could be something here like if current coordinate. Oops equals row. If I've gotten to the end. Right. Minus one.
Effulgent Covariate: Yeah.
Stochastic Panda: And current quarter equals. Oh, sorry.
Effulgent Covariate: You call it rows in calls. Yeah.
Stochastic Panda: Yeah. Then what does it mean to terminate? Here's where I would do return level.
Effulgent Covariate: Got it.
Stochastic Panda: Because now, right. I don't need to explore neighbors. There's no more to explore really. But I've gotten a good, well, in a greedy way. There's a nuance to this but basically we also need to argue that how do I know it's the shortest kind of doing it?
Effulgent Covariate: Greedy.
Stochastic Panda: Because as soon as I get to the terminal point then I'm going to return level rather than trying to go back up and add stuff. Which means if we manage to not get to our goal or terminating point then it basically suffices to just return minus one. So.
Effulgent Covariate: Yeah.
Stochastic Panda: And what else did I want to mention? Okay, so those are the main points. I think if we were to do this again or a similar problem after you practice, I think you would knock it out of the park with some neat code and maybe one or session or more. Because I really do feel like the building blocks are there.
Effulgent Covariate: Yeah.
Stochastic Panda: And just as a bonus, right, like assuming you had the solution, one bonus thing that you can do if you have time is to add some insights that you know about Java on queues. And so one of them just to think about and I'll throw it out there is when you want to use Q add versus Q offer.
Effulgent Covariate: Oh, are you asking me? Because I think I actually know the difference, like in terms of at least the definition. But isn't offer if you want to not have an exception thrown when, like, I thought, if you try to do add and you try to do that, you try to add like a null thing, you'll throw an exception. But offer, I don't remember what happens, but I think offer will not throw an exception. That's what I know the difference to be. But it could be.
Stochastic Panda: Yeah, yeah, that's essentially it is. They differ on the basically fail throw or fail exception, if you will, when you're trying to insert and, you know, whether basically it's the space or, sorry, the set of conditions where you want to throw versus just returning false.
Effulgent Covariate: That.
Stochastic Panda: Kind of stuff is nice to add if you had time to finish the problem and. Yeah. Okay, so that's my general feedback. I really like this problem because to me, it's not like hard in the sense of saying, okay, I know I want to do bfs, but there's so many little details that it's a really good one to practice, at least in my opinion, with respect to a timed interview. Cool. So that's my high level feedback. Any questions?
Effulgent Covariate: So. Well, I actually have a couple not related to this problem, but one question I have is, do. Do you know if there's any. So I've both seen and experienced the idea that, like, if you get really stuck on a problem and then, like, you come back to it a week or two later and sometimes it clicks, like, do you know if there's any science behind that? Like, why that would happen or because it seems really, you know, unless you practice it over and over, like some. For example, the, the meat or the first meeting problem that I found really difficult. Like, I actually sketched out every step on a whiteboard. And the day that I did that, like, I still was pretty confused. But then I came back to it a day and a half later. I was like, oh, you know, like, suddenly the visuals clicked, you know? Yeah, I don't know if there's any, like, reason for that or just sort of space repetition has been shown to work and I don't know, but, yeah, I don't know if you know anything about that.
Stochastic Panda: I haven't studied the science on it, but I do have some experience on exactly what you said. Like, the first time I encountered this problem, to be fair, it was while I was practicing graph problems. I got to it and I just remember, like, struggling a bit and it took me some time, but I got it. And then about a week later I thought, okay, I've done so many other problems, let me see if I can revisit some of the ones that I found tricky. And a lot of things just like clicked when I revisited the problem. So I would encourage that. Overall, the thing I usually suggest to avoid is overfitting, so to speak, to say, I'm going to try this problem so that I can solve it in less like ten or 15 minutes, which is possible with practice. But then it starts feeling like memorization a little bit.
Effulgent Covariate: Yeah, yeah.
Stochastic Panda: So that's why I like putting a little bit of time between a problem and doing some others and then kind of coming back to one.
Effulgent Covariate: Yeah. And then, so my other question, which may or may not apply tomorrow in a couple of days, space repetition works super well, but I spent at least like a day to a day and a half trying to understand the solution to let me get the problem number. It's called subset with duplicates, or, sorry, without duplicates, because subsets too. So the problem, like, the pretty easy problem for backtracking was if all the elements are unique and you're trying to get the subset, you just call. So you just combine the first element with the subset of the rest of the elements. But I've been struggling a lot with the, oh, here it's a problem 990. So, I mean, yeah, right now, like, I've been stepping through the solution, like drawing it out, and I am at the moment, I'm still having trouble, like understanding, like, you know, well, first of all, how someone would come up with that in an interview, but also like, why it's doing what it's doing. So I guess maybe if I'm still stuck on it next or. Well, okay, two questions. One is, do you think that problem is important enough to go over it if I don't understand it, like, or just, you know, forget about it, or. And then the other question is like, you know, do you think it would be worth going over if I still don't understand it, you know, next time or something? Because I. Yeah, that was, that's pretty much, I think it's the only problem where I've actually like sketched it out step by step and I still don't really get like, why it's doing what it's doing. Like most of the other ones, you know, either, like once I know the approach, I can code it up, or once I like, step through it, I can usually get it. But that one, I'm just having a lot of trouble because of the aspect that you can't have the duplicate elements and it makes the code harder to understand for me at least. So I don't know. Yeah. Do you think that. Yes. Do you think that problem would be worth going over if I still don't understand or just kind of move on and get as many other problems, problems as I can? I don't know.
Stochastic Panda: I would, yeah, I would say in terms of priorities, the first thing I think would be good to do is the first, what is it? 123456 710. Eleven sections of the neat code, 150. So that's starting from arrays and hashing and ending at graphs. And to your point, backtracking does happen there. So after we go through or you feel comfortable more precisely with the majority of those sections, then we can say like, okay, maybe you're at a point where you feel like you've got grass down. Like DF's. DF's is cool. Like trees. You've got the different methods there and can articulate. Like, you know, are you doing it in order, post order or pre order DF's and same thing with arrays, like you know what to store, etcetera. Then we can say like, okay, cool. Now where did we have the most questions remaining? And it could be on backtracking. Now, the second thing I would say though, like, okay, how important is backtracking compared with the rest of the ten sections there? I would say, I mean, it's like a second or third priority. The main things actually I would say that you really want to feel super, super comfortable with are sections one, two, three being raised, hashing pointers 2nd, 3rd, sliding window, trees and graphs. Those five just come up so often and they set the stage for a lot of things that I would make sure if we're in a time crunch, we prioritize mastery, if you will, on those five sections. And then, okay, let's deep dive into other stuff. So that's the general advice. Now, super specific practical though, like if you're applying it, if you're applying to a company that has a bunch of leak code problems tagged, that's another way to prioritize. So companies like Meta and Google are pretty heavy on graphs and trees. And to be fair, backtracking does come up sometimes, but not as often. So that's another way you could prioritize.
Effulgent Covariate: Okay, all right, so it sounds like what you're suggesting is like, maybe keep practicing different kinds of problems. And maybe if I think I've covered as much ground as I can, then if there are ones I'm still struggling with, then maybe can go through it, but. Oh, I guess so. My other question is, for future sessions, especially if we're focusing on coding, does it tend to work better if, like, does it tend to work better if I just, like, practice as much code as I can, you know, for however many days I need to and such, and then come back when I feel more comfortable? Or, or do you think it's better to sort of force myself? Like, okay, so, like, we need to have a mentor session in, you know, five days or less. You know, I need to practice as much as I can in those five days. I gotta. What do you think tends to work better? Like, you know, if, if I can keep myself accountable, should I just, like, practice as much as I can and then come back when I practice a lot? Cause I. I don't have any interviews on the pipeline, so right now I have time to, like, go off and practice for however long it takes me. I just don't know if you've seen, like, people fall off the bandwagon if they don't have a, like, like a mentorship session in a little while? I don't know, like, what's your experience with that?
Stochastic Panda: Yeah, it really depends on your style of learning. Like, my style is a bit of continuance and consistency. And what I like to try and do is say, okay, for the next two or three weeks, interviews or not, I'm going to do as much code as I can, priority one. And when I'm feeling a little bit tired of code on a given day, I'm going to go to system design, behavioral practice, because for me, that consistency is pretty key. Rather than, you know, saying, this week I'm going to focus on code.
Effulgent Covariate: Yeah.
Stochastic Panda: And four weeks later I'm going to pause code and then maybe come back to it. So my advice for is to have, I would say, our next session in a timeframe that you feel will be consistent, you know, whether that's like a week or two.
Effulgent Covariate: Yeah.
Stochastic Panda: And what we can do is we can aim for the next session, you know, be it in a week or two or three, whatever you're comfortable with to be, let's say, half coding and half something else, just to spot check and make sure you're keeping up or full coding. So that's my general advice, is to make sure we finish coding first before we start revisiting other areas.
Effulgent Covariate: Okay. Yeah. All right. So I guess that'll be up to me. But. But you're saying if I can stay consistent, you don't see any downside with waiting a little bit to have another session because for example, today maybe I could have gotten it, but I just haven't practiced graphing yet. So is it in some ways better to come in having practice what I can and then if I don't get something, I know it's some other issue than practicing.
Stochastic Panda: That is one other way. Another way to, you know, keep the consistency and to a degree accountability is if we could set up a timeline. So yeah, in two parts, right. To say like okay, by x date you feel you'll get to, let's say the first or be done with or gone through with the first four sections. Let's say arrays have two pointers, sliding window stack. Then what I can do is probe those areas in our next session so that after the next session you say okay, now we've, you know, probed enough in those first four. Now let's say, you know, how much time would you like for the next three or four sections and just kind of do it iteratively? That would be my suggestion because, yeah, my goal with the first coding that we did on that funny or interesting lexicographic one and today's bfs was to do level setting and baselines. And I think I have a pretty good idea now. So my suggestion would be to do a little bit more deep dive. For example, if you were to say, yeah, I've already gone through arrays, two pointers and sliding, then I would say cool, then next week let's practice on that. But if you were to say, hey, I want another x number of days or weeks to do those first three or four sections, totally fine and we can wait for that.
Effulgent Covariate: Okay. Yeah, I guess if that's a good approach, maybe what I could do is like say, because I have gone through several of the sections, but like maybe say like what? Focus on three or four of them, then maybe like you'll choose something from one of those and then you know, check on something like that, would that be a good thing to do, you think?
Stochastic Panda: Exactly, yeah, I would say three or four sections, coverage at a time and then we'll practice one or two problems from each.
Effulgent Covariate: Excellent. All right. Yeah, that sounds, sounds good. All right, well, thank you. And yeah, I think that sounds good. Then I'll, yeah, and like you said, you know, I'll try to, I mean, I kind of have been doing that in a way. Like if I'm burned out by doing too many coding problems, I like do system design or whatever and I try to switch between. So yeah, it's been working too. So yes, I appreciate the time and everything.
Stochastic Panda: Excellent.
Effulgent Covariate: Yeah.
Stochastic Panda: I would say keep it up. I've seen seeing improvements already. And let's proceed with that strategy of iterative deep dive on code when you're ready with, you know, the first three or four sections for next. And while you're doing that, when you say, hey, I just need a break today or whatever for. Or something else. Yeah. Then behavioral assistance science. So that when we get there, we'll refresh on that, too.
Effulgent Covariate: Yep. All right. Excellent. All right. Good rest of your day.
Stochastic Panda: Thank you. Eric and I will talk to you later. Have a good weekend.
Effulgent Covariate: You, too. Bye.
Stochastic Panda: All right, bye.