Interview Transcript
Hurricane Automatonyour favourite apps … Use Gemini to generate drafts and refine content, plus get Gemini Pro with access to Google's next-gen AI
Hurricane Automaton
Hurricane Automaton
Stealthy Elephant: So my name is Stealthy Elephant, and so the first 5 minutes is a brief introduction of each other. And I want to know where you're currently in the interview process. The next 45 minutes will be 2 technical questions, and the last 5-10 minutes would be a debriefing feedback. Does it sound good?
Hurricane Automaton: Yeah. Yeah.
Stealthy Elephant: Okay, perfect. So my name is Stealthy Elephant. I've been working as a data engineer at Atlassian for the past 5 and a half years. Done a multitude of, you know, interviews for senior staff, anyone you can name it, for behavioral, system design, everything. And I've been working with interviewing.io for the past 2 years just for helping out. And I work with multitude of microservices on the data engineering team. So yes, can you tell me a little bit more about yourself? Which role you're applying for? Where are you in the interview process?
Hurricane Automaton: Yeah, so I'm interviewing for the L5 position, uh, and, uh, regarding interview stages, I've cleared all the on-sites and— sorry, not on-site, like phone screens and I have my on-sites upcoming targeting companies like [REDACTED] right now and also [REDACTED], [REDACTED]. Like, yeah, I have like, yeah, 10+ years of experience, you know, mostly as backend engineer working in one of the other top-ranked companies. So yeah, that's a bit background about myself. Nice.
Stealthy Elephant: Perfect. So you have a few and you're going for senior engineer roles?
Hurricane Automaton: Yes. Yes.
Stealthy Elephant: Perfect. Perfect.
Hurricane Automaton: Okay.
Stealthy Elephant: Yes. And do you have any final rounds coming up or are they all like beginner rounds, middle rounds?
Hurricane Automaton: Oh, no, no. These are, these are final rounds, like, which are coming up. So, uh, yeah, in a week's time, like, I'll be having final rounds with [REDACTED] and And also have rounds with [REDACTED]. Yeah, so a few rounds coming.
Stealthy Elephant: Oh, perfect. Yeah, perfect, perfect. Yes. All right, that sounds great. All right, so let's get into the interview process. Do you have any questions before we go ahead and get started?
Hurricane Automaton: Uh, you mentioned two questions, like, so, um, yes, just like, so is it more like [REDACTED] style, like, you know, I would anticipate, like, or because sometimes people ask like one question which is more difficult, like, and, uh, but again, maybe we, we will see. Like, thank you for the clarity about that you'll be asking two questions. Maybe if I had to ask you, uh, do you anticipate the difficulty level of the two questions, um, to be similar? Or like, does the first one, like, the second one build upon the first one? Like, uh, what is it going to—
Stealthy Elephant: Yeah, so there's two different questions. The first question is like a preliminary, you know, [REDACTED] medium-ish with a little bit of my twist. And then the second question is a question that I made myself, but you know, it's a good persuasion of past [REDACTED] questions and everything that I worked with before. So that second question is its own, and that's a little bit on the harder side. But let's say you finish both easily, we can, you know, I can try and figure— I have a third question in the bank if you need it.
Hurricane Automaton: Oh no, no. Okay. Yeah. Okay.
Stealthy Elephant: Let's, let's do it.
Hurricane Automaton: Yeah.
Stealthy Elephant: All right. Perfect. Let's do it. So it seems like you're gonna C++, correct?
Hurricane Automaton: Yes. Yes, I'm going to use C++.
Stealthy Elephant: Okay. I'm going to copy and paste the question for our first one. And we'll go ahead. Okay.
Hurricane Automaton: Okay. Okay.
Stealthy Elephant: Okay.
Hurricane Automaton: So given an unsorted array of integer nums, return the length of the longest consecutive elements sequence. So, okay, it's the longest, uh, sequence. So in the first one, the output is 4 because, uh, longest consecutive element sequence. Okay, consecutive. So 4, 1, 3, 2, right? So, okay, okay. And in the second one Uh, it is 9. The reason is, uh, basically all the first 9, uh, no, okay, 0. Oh, okay, so, uh, the reason this is 9 is because of this, right? Like this part, like, uh, which is 1, 2, 3, 4, 5, 6, 7, 8. Yeah, okay, from 0 to 8 you have all the numbers like in this block. And that's the reason why the answer is 9. Uh, here, uh, it is 3 because of this. Okay, uh, and, uh, it is a subsequence. So, all right, uh, and constraints are given. The constraints are like, okay, nums— like, so this gives me some hint about, okay, that it should not be a Uh, anyways, we cannot sort. If we sort things, uh, yeah, return the length of the consecutive element subsequence. Okay, uh, in this case, uh, because 4 and 1, 3, 2, like, they're still in the same, or like Like if we sort, things will get screwed up. Like, so no sorting in this case, right? Because if I screwed, like, you know, if I, if I sorted it, uh, in that case, like, uh, so basically here, like, you know, we are seeing 100 and, uh, I see, and 200, they are not in sequence actually. Okay, okay, okay. Length of the consecutive element sequence. Yeah, can you confirm please, like, if I'm understanding this, uh, question correctly? Like, here the answer is 4 because it is, uh, 4, 1, 3, 2. Like, those are the elements contributing to the output. Actually, I cannot hear you. I cannot hear you. Are you muted by any chance?
Stealthy Elephant: Yes, I was muted. Yeah, so this one on line 11, you see— yeah, you see this? When you just— you're 1, 2, 3, 4. It's 1, 2, 3, 4 in an array like this. You can think of it as— that's why the output is 4, right? And there's something right here. It'll be 0 to 8. Yeah, yeah, that's why. And then over here is 0. 1, 2, right? So that's why the output is 3, 9, and 4. Does that make sense?
Hurricane Automaton: Correct, correct. And when you say like the longest consecutive element sequence, like my question is this, like that in this question, like is it like a, a subsequence kind of thing that 4, uh, I'm actually, um, like what kind of, what could have disrupted? Nothing, because you're already like putting in 200 and it's still 1, 2, 3, 4. So is it as simple like, like, I'm, you know, like, I'm thinking here, like, is, is this just simply like sort and give me like, you know, whatever is the longest sequence? Like, is that the answer?
Stealthy Elephant: Or is it more on the side of like, you know, that this would be 9, 11, line 11 would be the answer, right? You basically want the, the longest consecutive elements, right? So whatever the left of this line 11 is.
Hurricane Automaton: OK, OK, so basically the— like in this, like, like I understand this part. My question was that is this answer because of the array in the sequence, like, you know, 4, 1, you know, like 3, 2, or like— just a second, let me think if I am— I want to. Yeah, you know, like, if— like, one approach, tell me if it is right or wrong. Like, basically I just sort this array, right? And look for elements, like, you know, in the sorted array, like, you know, how many consecutive elements can I find in the sorted array? And, uh, that will give me the answer. Like, like, I, I— when I find the element, I just go and, like, you know, keep looking for the sequence, right? Like, so Is that, is that on the right track?
Stealthy Elephant: Yeah, that's on the right track.
Hurricane Automaton: OK, OK, so now the complexity of that approach is n log n and like if I'm allowed to sort like modify the input then we will not need any extra space and we'll be able to do that in n log n. Now you have given me a like length of this. OK, OK, OK. So, uh, OK, now I see it is, um, so like the alternate approach to solve it like in linear time. Again, I think now I see that this is the question which like I have in mind. So basically like I can create, uh, we can solve this in a linear approach by putting these items like in, uh, HashSet, uh, and, uh, then basically looking for, uh, the elements, like, you know, how many consecutive elements are present in, in, in the HashSet. Um, and, uh, can this have duplicates? I think yes, like here, uh, this example had duplicates. Okay, so now duplicates, does that matter? I think for this answer it should not matter. So yeah, it will not matter. Like it can still be a HashSet versus a HashMap is what I was thinking. So yeah, it would be HashSet, create a HashSet from this and then, and then simply go over the elements and yeah, I think one thing is about like potentially duplicates. Yeah, I think I have an approach there like, like, you know, I believe I have. I have solved this in the past, so basically what we would do is like say if, if after, because we are not sorting, it's possible that we will see 4 as the first number here. And now what I'm going to check is like for 4, I'm just simply going to check is does 3 exist? If 3 exists, I do not. Go in this loop. Like, basically, I'll not try to find the answer for 4 because I know that, um, uh, when I, when I reach to 3, I'll, I will find 4. And like, similarly, like, for 3, like, we will check, hey, is there 2? If, if 2 exists, uh, then like, if the previous number exists, then I don't go in this consecutive finding loop. Uh, what I'm going to do is basically My goal is to start with the minimum number, like in that sequence, like whatever is the minimum number in that sequence, we'll start from there. And in that way, we'll be able to find all the answers.
Stealthy Elephant: Maybe I can code and maybe that, uh, yeah, I think that's the right direction though.
Hurricane Automaton: Okay, you said right direction, uh, like, uh, is there some flaw there? Like, uh, still, uh, again, no, I would say you're in the right direction.
Stealthy Elephant: In the right direction of the hash set.
Hurricane Automaton: Okay, okay, so let me, uh, get started. Uh, I, I will code this and then, uh, uh, so okay, okay, longest sequence, like, so okay, int longest, uh, say consecutive, uh, consecutive sequence, uh, and this will take our array, like, okay, int a vector of int nums, and, uh, it's this. Okay, and now the first step is to make this, uh, HashSet. So unordered, unordered set of int And this is non-stop. This is our— okay, insert equals to non-stop begin, non-stop And okay, and so this will create our HashSet. And now basically for int n in nums, we go over this. Now if, and then we'll have our int longest sequence is equal to 0. I assume it's 0. Now if, uh, if n_set, uh, say, .contains— if it doesn't contain, I'll make it simple. If it does not contain, uh, n - 1, then I will go in this loop. Basically, this is— if, if this happens, like if it doesn't contain the previous number, that means Uh, this means that this is the starting of the series. Okay, now in this case, while n_set.contains our Okay, n plus 1, uh, and maybe int curr_length, curr_len is equals to 1, and we can, uh, okay, uh, our constraint had that, okay, it can be no numbers are possible, so has to start with 0, and now curr_length is 1. And, uh, yeah, while n_set contains n+1, like I simply do n++, okay? And, uh, like keep looking for the next number. And yeah, okay. And, uh, here, uh, what we can do is, uh Yeah, uh, longest sequence is equals to max of longest sequence and from our cur_len. And now we need to increase the cur_len here, uh, cur_len Okay, uh, plus plus. Okay, so we keep looking for— no, no, no, no. Okay, so this is not, uh, yeah, like, okay, I, I'll— I, I think this should, uh, work, but I'll clean it up a bit. Like, uh, return, uh, longest, uh, sequence, uh, like Okay, and plus curl length, I can do this curl length, basically this, and I can get rid of this completely. Uh, yeah, so basically here, and, uh, our constraints were this, uh, 10 to the power 9, and the number can be 10 to the power 5. Uh, is this a problem? Like, I'm thinking like in terms of summation, can it cause any problem? It will not cause an integer overflow here because, uh, the max number is 10^9, which is within the int limit. So it will not be a problem even though we are doing a sum here because this will never increase beyond that. So safety check, like, yeah, no more, no more conversions needed. OK, so just a quick run through, I think. Yeah, I'm— I think this is the solution. I'll do a very quick run through for this problem and then— OK, so. So yeah, let's think of this example like our— like the first example we created an unordered set like in the unordered set basically has all of this. Gives us, uh, order one axis. Longer sequence starts with, uh, 0. Now this is also valid for our use case, like where we had 0 length, because then it will not enter the loop and will return a 0. Now we go over the numbers, like n, like the first is 100. I set curr_len to 1, so at this point, uh, so n is basically 100. Now when it is 100 Curl length is 1. Like, we check, like, hey, does, does it contain a 99? Like, your nset contains 19. Okay, I think this is, uh, yeah, no, this is correct. Yeah, okay, so does it contain 99? Uh, the answer is no. In that case, we will enter this loop, and what I'm looking for here is like, okay, does nset contain n plus curl length? Curl length is initially 1, so n plus curl length is 101. Like, does it contain 101? The answer is no. Uh, if it is no, then I don't enter the loop. Fine. And longest sequence becomes whatever was the previous versus current, which is 1. So at this point, longest sequence becomes 1. Now, uh, for 4, next element is 4, uh, we go here, current is reset to 1. We check like, hey, does it contain 3? Like, uh, and the answer is yes. If it contains 3, fine, we ignore it. Similarly, next number. So 1, like we check like, hey, does it contain 1? Like, uh, does it contain 0 is what we'll check, like n minus 1. And the answer is no. So in that case, uh, while— now this is the, uh, part where we are entering this while. So, uh, does it contain, um, oh this was incorrect here. Like, sorry, we should have never reached— oh no, we would have reached that. Yeah, that's correct. Okay, so in this case, like, uh, curl length starts with 1. Like, while nset contains n plus curl length, which is n— is n is 1, so does it contain 2? Uh, and the answer is yes. So we increase the curl length, curl length becomes 2. Now next loop, like, we'll check, hey, does it contain 3? Yeah, fine. Uh, okay, let me continue this once. Uh, so yeah, does it contain 3? The answer is yes. And, uh, now curl length becomes 3. And does it contain 4? Uh, and the ans— so when curl length is 3, we are looking for, hey, does it contain 4? And the answer is yes. And if the answer is yes, then the curl length becomes 4. Yeah. And then we look for next, which is curl length— is, is 5 there? And the answer is no. So yeah, fine. I think this is, this is my solution. Now let me know if you want me to run it or if you're satisfied with this.
Stealthy Elephant: Yeah, I think, I think you get to run. Yeah, let's run it.
Hurricane Automaton: Okay, so let's write it like, okay, okay, so vector of int, our, like we had this. Okay, and input is equals to our vector of input. Yes, this. And now let me include— sorry, what is this? Okay, maybe complaining about Okay, so now let's include all of this. #include <unordered_set> and <vector>. Uh, anything else? Likely no. Okay. And no semicolons here. Okay, fine. Okay, so we have included all of that. Now we have initialized vector, and now let's do cout of, uh, of our longest consecutive sequence on, on our input. And, uh, and then, okay. Okay, so I would expect an answer of 4. Okay, so this was correct. Now, uh, let's just check this case. A single number and the answer should be 1. Okay, answer is 1. When we have no input, like, uh, it should be 0. Uh, okay, let's see. OK, 0. Yeah, I am. Yeah, let's just— I think this is the same as the previous one. So again, I think I'm happy with this solution. Yeah, yep.
Stealthy Elephant: Any edge cases?
Hurricane Automaton: Yeah, edge cases. So right now. Uh, let me think. So your edge cases are like this, the numbers like being, you know, like, uh, at the corner. Yeah, I, uh, like actually, like, so because the constraints have been given already in this constraint, like right now, uh, let me think of like say 0, like, you know, let me just work with one negative number example. I think that should be good, but let me just check. Like, so here the answer should be 2. Okay, so this is correct. So no negative number problems. And now, like, our edge case of 1e9, uh, and, uh, I don't know how to— okay, I can't do that. Okay. Yeah, I cannot think of any edge case. Let me know if you spot something like which you think will not be covered here.
Stealthy Elephant: Yeah, maybe like, so I see that for the one of them, empty list or maybe just one number. Okay, so we did that. Yeah, perfect, perfect, perfect. Everything. Yeah, I think you should be good though. And where is the time and space complexity?
Hurricane Automaton: Yeah, time is order n and space is also order n because we are creating this HashSet additional to the data structure which we already have. So yeah, we're doing it in linear.
Stealthy Elephant: Yeah, perfect. All right, you're good. I think everything's good for this one. Let's move on to the next question.
Hurricane Automaton: Sure.
Stealthy Elephant: All right, let's do it. Okay, I'm gonna— so this question is something I created, so yeah, I think you have fun doing this one. Here you go.
Hurricane Automaton: Okay, okay. So you are given— you are a landscape designer working on a vertical cliff covered with vertical cliffs. Okay, um, the cliff is modeled as a 2D grid. 1, 1 is a tree, 0 is empty, raw Okay, thank you for this. Uh, okay, so, okay, I have a question. Should I ask my interviewer to read the question for me, or am I expected to read? I know, like, sometimes the reason is like I can miss something.
Stealthy Elephant: Yeah, so I would say no, no, so whatever I'm copy pasting, it's— you can read it, you can also talk to yourself. I would prefer you read it out loud just to have that communication aspect, right? Just to show that you're thinking. A lot of interviewers don't like it when you're reading in your head and just like 20 seconds of silence.
Hurricane Automaton: You can do it.
Stealthy Elephant: Yeah, that's the best way for you.
Hurricane Automaton: No, no, no, no. I, I speak it like, you know, that's not the problem. Like sometimes I found it useful for the interviewer to read the question because they will almost certainly speak out all the edge cases and all like, you know, like it would be much natural like to the miss the part of misunderstanding is really reduced. Like, if, if my interviewer is reading the question for me, because they will explain it very nicely, like, like, and save me like 3-4 minutes at least.
Stealthy Elephant: Yeah. No, so for this one, no, for this one I'm not gonna— I don't do that because I would like you to read the questions.
Hurricane Automaton: No problem.
Stealthy Elephant: Up to you to ask me the question because I want to make sure that I'm thinking about the worst case scenario, right? What if you're like their accent is thick, they don't really want to help you. So that's why I'm trying to recreate. So I would like you to read the question. Any question you have, I'll answer it.
Hurricane Automaton: Okay, so you're working on a vertical cliff. Now I, I like, okay, so this part like is right now like something which I need to think. What is a vertical cliff? Fine, like let's see. Uh, uh, the cliff is modeled as a 2D grid. One is a tree. Okay, so in your example I see many trees. 0 is a rock, empty rock, empty rock. The bottom row is solid ground, the bottom row is solid ground. Okay, uh, okay, 2 trees are connected if they are adjacent, up, left, right. Okay, a tree is considered stable if it is connected through the other trees to at least 1 tree in the bottom row. Okay, fine. If a tree is not connected to any of the tree, it will fall off the cliff and disappear. It will fall off the cliff and disappear. In this example which you have given, all the trees are connected, right? Because everything seems to be connected to this one, correct? Line number 37. Okay, so in this case, like, no tree will fall off as such. OK, a tree is considered stable. OK, fine. You are given an n, uh, m cross n grid. m and n are also given. 0, a coordinate, and a coordinate cut is equals to RC representing the tree you cut down. OK, cutting this tree like, OK, I'll be given only one code, like one coordinate here, 1, uh, Okay, so I'll be given one RC representing the tree you cut down. Cutting this tree means the RC becomes 0 first. Okay, after that, all the trees that are no longer stable, uh, no path to 1, so the ball will also fall and become 0. Return the resulting grid after all unstable trees have fallen. Okay, okay, okay, it's a good question. Uh, so in this example you are saying, uh, if we cut 1, 3, 1, 3, so this is our 3, uh, okay, it's a little off. Okay, so 1, 3 is cut, so this one, right? Like, so if we make this x, uh, like say a 0, uh, in that case Yeah, like, uh, these will fall off, right? Like, uh, the last 3 here, uh, and these 2. So the output will become 0 space 0 and 0. Is my understanding correct?
Stealthy Elephant: Yes, correct.
Hurricane Automaton: Okay, that's correct.
Stealthy Elephant: Okay, let me give you— let me give you a second example just to make sure.
Hurricane Automaton: Sure. Yeah.
Stealthy Elephant: Start. So example 2 is going to be—
Hurricane Automaton: okay, there you go.
Stealthy Elephant: Yes, what will be the output based on the input?
Hurricane Automaton: Yeah, the input is same, like, okay, so in this case the output will be basically this, right? Like, uh Only that original tree falls, which we fall and like, and that's it, right?
Stealthy Elephant: Yep, perfect. Okay, you're good. Oh, you understand the question?
Hurricane Automaton: You can start it. So in this question, I'm thinking like, you know, the initial state like sort of does not matter to me, like whatever it is, like I can simply go ahead and make this part 0, like because you'll only give me one cut. So I will go ahead and make that, uh, cut. And now, uh, what we can do, like, I'm thinking like a depth-first search, uh, here, uh, or, or a breadth-first search, because usually breadth-first is easier, uh, to, to code. So in this case, like, what I will do is I'm going to Hmm, like, one easy thing I can do is like create a copy of this array, like, you know, like the grid completely. And then I go ahead and start from the bottom, like bottom row. And yeah, and then like for the bottom row, like I'll just look, are there any ones? If there are any ones, what I'll do is like from that position I'm going to start my this depth-first or like breadth-first search and I'll continue and you know, like in all the direction till I can find a one. If I can find a one, I'm going like those trees are certainly going to be there. Now, uh, and we'll do this for each of the trees. Now we don't need to do, like, say, uh, I'm thinking, like, you know, because this algorithm will work, but like in the worst case scenario, like say if everything was just all ones, then it's a very expensive algorithm because I'll be like repeating it again and again and again unnecessarily. So I can also mark the grid as visited so that we don't need to repeat. Now, yeah, am I, am I on the right track, like, for that part?
Stealthy Elephant: Yeah, you're on the right track.
Hurricane Automaton: Okay, okay. So now in that case, like, Now, now already I think I am explaining two data structures, like basically two different, like for visited and for that. I think what I could do potentially, again, this is raw thought right now, maybe it's incorrect. What I would do is maybe I'll start marking them as a special value, like say because this is 0 and 1, maybe I'll start marking them as -1. So, uh, like I start from here and then I mark this as -1, and then I go up, I say, okay, hey, I can reach this one, fine, -1, -1, uh, anything I can reach I just mark temporarily -1. So -1 is, uh, is, uh, -1 is a special use case. Like here, it's helping me with two things. Number one, it marks the nodes as visited. So they say that, okay, this is visited, so I will not visit it again. Also, it marks the final state like for me, which I want. Like, and now here again, like I will go here and like start marking -1, -1, -1, -1. And at the end, like again, I will go through these arrays again, like, you know, this grid again. And anything which is -1 will be the only one which will become 1. Anything which is remaining, like say if there was disconnected, like say 1 here remaining, Yeah, that becomes 0. So like, I, I will just make, flip that to 0, and only -1 becomes 1. Yeah, that way I think we'll be able to find all the trees in the final state. Let me know what you think.
Stealthy Elephant: Yeah, I think it's good. I think you're on the right track. I'll definitely let you— just a heads up though. You do have, I would say, 20, 20 minutes, 20, 21 minutes. Just be patient yourself.
Hurricane Automaton: Sure. Okay, okay, thank you. Uh, so let me, uh, yeah, like, let me write this one. And output is a void, basically the same grid. Okay, so void, uh, and, uh What is this? What should we call this function? Landscape, fine, we'll call landscape. Okay, and it has a vector of int as input called grid, grid, and And we have our cut. Cut is a pair. So we have a pair of int comma int called cut. And those are the input which are given to us. Now, hmm, okay. Okay, okay, okay. So once— okay, int m is equals to grid.size, and n is also grid .size. And okay, and now step 1, no steps needed. Okay. I'm thinking of edge case also, like, you know, if there's only one row, like, is there any input constraints here?
Stealthy Elephant: Like, no, I would say, I would say ones and zeros, but I think I would suggest just having a solid solution and then let's figure out the edge cases at the end.
Hurricane Automaton: OK, OK, sure. So fine, we have M and N for this. And now let me— OK, so I want to do a BFS. OK, so I'll start, say, auto our BFS. And I don't need BFS, can be in place, so nothing special is needed. Like, so fine, just a second. So I start with the final row and Oh yeah, first thing we make is the cut, right? So grid of— grid of— okay, let me simplify this. And cut X and cut Y. Okay, so grid of cut X. Okay, cut X and cut Y will be within our grid, right? Okay, uh, is equals to 0. So we cut it, uh, so the grid has been cut. Now for, um, int, uh, say R is equals to 0. R is, uh, okay, what we are going to do is Just a second. Maybe I'll use my paper pen so that I'm not like, you know, doing back and forth. I'll get back to you. Yeah, OK, so great. Yeah, what we want to do is we want to start from the bottom. So the last row, OK, and for the last row and We have 4 directions, all 4 directions are there. Okay, 4 directions are there. And for each direction, like we start with the bottom row and we say, okay, if it is 1, fine, we start it. Okay, we'll need a queue. And for this, and then we go up. Okay, and up. Down. Okay, down is fine for the BFS, so I don't need to go—
Stealthy Elephant: yeah, okay.
Hurricane Automaton: Queue up. Okay, okay, so, um, okay, we'll need a queue, uh, queue of int. And, uh, because this will complain, I'll include the queue #include <queue>. Okay, and, uh, where is it here? queue<int>. I'll simply name it queue for now. And for, uh, the last row, basically the row is fixed. So yeah, for some i is equal to Like, this is for each column of the last row, we'll start a DFS. Uh, okay, so yeah, let's say for i, i and i is 0, and i is less than each of the columns which we have, so it's n and i++. And what we are going to do for each of this— now, if, if grid , i is basically the last row, so it would be m - 1. If grid is equal equals to 1, then we want to do the BFS from here. And what we'll be doing is like, if this is the case, then q.end— okay, so this q will not be integer, it will be a pair of int, pair of int comma int. And q.end push M minus 1, M minus 1 comma i. So that's where we will start. Now while the queue is not empty, while queue.empty, uh, till the queue is not empty, we are going to do the BFS. Uh, so here now, uh, okay, so auto say r comma c is equals to q.front, okay, and we will q.pop, okay. And we remove the element from the queue at this point. And now, uh, we will make it -1. And, uh, grid of, uh, r, c is equals to -1. So we make that -1, and now, uh, we will have, uh, directions like here, uh, again, uh, int, uh, dr is equals to 0. Okay, int, uh, yeah, it's fine, dr, dc, uh, is BC 0 1 comma 1, uh, 1 0 minus 1 0 and 0 and minus 1. So these are the 4 directions which we have, uh, okay. And now, uh, we'll explore all the 4 directions. So for, uh, int, uh, say k is equals to 0, k is less than 4, k++. Okay, uh, like, uh, yeah, uh, int nr is equals to r plus dr of k. Okay, and this will be tc of k. And now if this is a valid position, and, uh, yeah, it's fine, I think. Yeah, okay. If, uh, if nr— like, sorry, if nr is greater than or equal to 0, and nc is also greater than or equal to 0, and our nr is less than— nr should be less than n— n—
Stealthy Elephant: n—
Hurricane Automaton: m. Okay, and nc is less than m. Uh, okay, and grid of NR, NC is equal equals to 1. Now in that case, we want to explore it, so Q.push, uh, okay, NR, NC, and Yeah, I think, uh, and, um, okay, okay. And here, like, we are going over each row. Yeah, I think this is the main iteration. And, uh, one second, let me make sure. Now here, is it possible that I add it multiple times? No. Uh, One second, uh, like I'm looking if it is 1, then I'm adding it, like I'm simply adding it to the queue. Now it's possible, so I think I may want to do this here, like so. So grid of nrmnc is equals to -1 right here, and this I can eliminate and move it up. So, so the first thing before pushing is like, or after pushing, is this what we'll do this here, M - 1 and i -1. Okay, so now, yeah, and now once this happens, like we need to loop over this. So for int i is equals to 0, i less than m, uh, m, uh, i plus plus. And, uh, for int j is equals to 0, j is less than n, j plus plus. Okay, um, if grid of, uh, i, uh, j is equal equals to -1. Basically, grid of i, j is equals to, uh, is grid i, j equals to -1, then it becomes 1. Uh, yes, then this is 1, else it is 0. Okay, okay, I think Because I'm short of time, I think this would be the solution which I had in mind. So Phase 1, like, you know, this is the BFS part. Phase 2 is the final state part, like is here. Yeah, let me know. I can maybe do a dry run like here, but dry run might be complex.
Stealthy Elephant: No, it's fine. You can dry run. I can—
Hurricane Automaton: okay, let me use a simple example for the dry run because that would be better rather than these ones. Okay, so, so say, uh, here line number 59, I will simplify this. Uh, okay, say I'll simplify it more. Okay, so OK, let's think of this was the tree and no, not a good tree. OK, let's think this was the tree. In that case, like say if I cut this one, like I do not know, you know, like is dry run better for this problem or like should we try to run it? Because I think running is better than dry run. It's too complex.
Stealthy Elephant: No, yeah, so just to get a heads up, I will give you, uh, 10 minutes to do like 5 to 10 minutes. So by all means, if you feel like you can run it, then go ahead.
Hurricane Automaton: Yeah, I'll run it, like, you know, in this case, because these grids one, like, I'll just be talking numbers and I'll be babbling a lot, like, so yeah, I think it's— yeah, so okay, so we have our input, like, here, and like we had the Answer. Do you mind pasting your original? Okay, and let me just map this out. Okay, so grid, we have this grid. Ah, come on. Okay, vector of— vector, vector of int, uh, sacred, uh, okay, this is equals to our example. Oh my God, okay. Where am I? I'm here. Okay, so, okay, uh, now let me just make my own example and we will be able to understand. So, uh, okay. So this is a 3-row example. All trees are connected in the beginning. Let me just, let me just, OK, let me make it even simpler. So in this example, I'm going to cut this, the bottom one, and everything should be 0 at the end because that's the bottom one, right? So let's try with that. OK, so let's— OK, how would we check? I need to write, uh, okay, uh, for— oh no, not, not— yeah, like for int i 0 and i grid.size; grid++. Ah, come on, i++. And int m is equals to grid.size, okay, okay, and n is grid .size, okay. So now I, okay, and let me just do this, okay, for j j is equals to 0. There is n and this is m. Okay, and just do a cout and then okay, and here cout grid of, uh, i, j. Okay, and no endl, comma. Okay, and, uh, yeah. Okay, so, and now let's just call this, uh, landscape, uh, landscape_on_grid. And let's cut our 0, 1, 2. So 2, 2. Poop. Okay, that's one point. Okay, uh, 2, 2, and, uh, yeah, let's see. Uh, okay, okay, okay, this will also complain about this. Uh, just a second. Uh, okay, all these, like, uh One second, let me quickly fix first this. Like, you know, here, uh, this has to complain. Uh, okay, m_grid_size unused variable. Okay, line 136. 136 says m is unused. No, m is used. Okay. Let me stop this and reset this once. And let's—
Stealthy Elephant: oh wait, uh, I think you're missing an extra row. No, 134.
Hurricane Automaton: 134. Uh, oh yeah, I just created, uh, like, I, I thought I'll just use this example. Yeah, and here Yeah, uh, okay, there is some add heap. Okay, overflow. Where is this overflow? Uh, line number, line number. It's not giving me line number. Okay, let me, uh, just do some couts to see where this is giving Yeah, okay, 69 at 69. Okay, uh, okay, in the beginning let me just undo this landscape and just let me reset this. I just want— okay, uh, the simple—
Stealthy Elephant: yeah, so do you want a quick hint or do you want to just keep going?
Hurricane Automaton: Yeah, yeah, yeah, yeah, please, please. I think that would be helpful because here I think, yeah, Right now itself, without even calling this function, I got this error.
Stealthy Elephant: So, uh, okay, so, so first thing off the bat, I want to see if you're going to come back to it, is, okay, look at— let me see, let me see if I note it down. Line— what is it? So you have— give me one second, I'm looking at it.
Hurricane Automaton: Sure.
Stealthy Elephant: Oh my God, my thing is lagging a little bit. Give me one second. My thing is— No, no, uh, okay, so, so there's a part where you're doing the BFS check, right? You're seeing— you're doing NC less than N, right?
Hurricane Automaton: Yeah, yeah.
Stealthy Elephant: Think about where is it going to be less than.
Hurricane Automaton: Oh, okay, uh, so Sorry, line number 90. Are you seeing line number 90?
Stealthy Elephant: And see, uh, yeah, NC less than— NC less than—
Hurricane Automaton: oh, okay, yeah, yeah, there's a problem here. Uh, NC should be less than N, not M. Uh, that's one. But like right now, like actually I have not even called that function. If you notice here, I have commented that.
Stealthy Elephant: Yeah, yeah.
Hurricane Automaton: Yeah, and like the error which we were seeing is like some— oh, okay. Sorry. Yeah, it's just—
Stealthy Elephant: you're talking about— so yeah, so look at live.
Hurricane Automaton: Yeah, yeah, yeah. Like here, I think there was a problem here later. Copy paste, copy paste kills us more. Okay, so yeah, good. Okay, so this is working. Now let's call the landscape and see what happens. I expect everything to be zero. Okay, let's run it. Run, please. Run, please. Okay, yeah, everything is zero. So this is correct for this example. Now let me just make one more one here. So that means there is at least one connection. Now in this case, only— Oh yeah, yeah, yeah, let's do that, let's do that. That's better. Okay, actually we modified your test case, right? So that's why I was asking if you have the original test case, that would be better because I, I updated it inline for, for my—
Stealthy Elephant: Oh, oh, you're saying—
Hurricane Automaton: Yeah, okay, okay.
Stealthy Elephant: Yeah, uh, no, uh this.
Hurricane Automaton: Yeah, this one. Line 48.
Stealthy Elephant: Just copy and paste.
Hurricane Automaton: Okay, okay. Yeah, the problem is, you know, it's not— yeah, yeah, no problem. Let's, let's do that. Like, I think there's still something we changed with this input. If you have the— oh, you, you modified it now? Okay, okay.
Stealthy Elephant: Yeah, yeah, this one. Uh, but there's no commas though.
Hurricane Automaton: Yeah, I think—
Stealthy Elephant: okay, let me just copy and paste it for you.
Hurricane Automaton: I appreciate it, thank you.
Stealthy Elephant: Uh, okay, where is your case? You are in line 135. Okay, 135. Yeah, okay, right. You're gonna see your— you're gonna see There you go.
Hurricane Automaton: What did you use for this? Did you just use some— our GenAI to convert this? Okay.
Stealthy Elephant: No, so I have my own specific test cases for— I expect like C++ or anything, so I always have it ready to go.
Hurricane Automaton: I see. So here, like we need to— let me reset this first and And where are we making the cut? The cut is at 1, 3, right? Okay. Okay, cut 1 and 3. Okay, let me just once call without this, you know, just to print it nicely here on this board and then with the lens. Okay, so this is the original. And now we are cutting 1, 1, 3. Okay, so in this case, okay, only that one should be impacted, nothing else. Okay, yeah, so only that one is impacted, nothing else. And yeah, yeah, go ahead.
Stealthy Elephant: Now let's remove the bottom ones.
Hurricane Automaton: Uh, let me see. Yep, yep, yep. Like maybe we can just remove, uh, from 135, uh, the bottom row, the, the another tree, this one right here.
Stealthy Elephant: Okay, yeah, you should be good now.
Hurricane Automaton: Okay, okay, okay. So let me first reset this, uh, print this for us like before, uh The grid is cut. OK, so this is the original tree and we are cutting one tree. OK, so OK. Alright, hopefully yeah, OK, I think it is correct.
Stealthy Elephant: Yeah. What is the time and space complexity?
Hurricane Automaton: Yeah, time complexity is m cross. Let me think. M cross n because we are We are not, you know, like we maintain this grid and like, you know, like in that itself. Yeah, we don't repeat ourselves. So time complexity is M cross N worst case and space complexity again.
Stealthy Elephant: M what?
Hurricane Automaton: M times M. M and basically the grids. Yeah, M times N. Sorry.
Stealthy Elephant: OK, OK, yeah.
Hurricane Automaton: And space complexity wise, like. Mostly we are using the grid, but we also have a queue. In the worst case, the queue can grow M times N. So yeah, so yeah, will it grow M times N? Uh, I don't know, like, yeah, maybe we can make an edge case like, you know, yeah, good.
Stealthy Elephant: Okay, okay, sounds good. All right, you finish the question, I'm going to the feedback section.
Hurricane Automaton: Okay, sure, sure, sure.
Stealthy Elephant: Yeah. Okay, so I would say— so the way I always structure feedback are in 4 sections: strengths, okay, room for improvement, open notes, and what you should do differently in the next interview. And I think I hear you turning the paper to write notes, but all this is going to be on the—
Hurricane Automaton: oh no, no, on the feedback.
Stealthy Elephant: You're gonna get it, you're gonna get everything in the feedback session, so no reason to write it down. Uh, So the strengths is I think you did a really good job of understanding the question. Maybe you got, uh, you're asking, you're asking clarifying questions to make sure you understand it, like the first one, and that's good. Sometimes people just dive in, they just make assumptions, right? Uh, and I would say you're able to solve the questions super fast, first one. And the second one, you're able to solve it, you know, with a little hint or two, right? So I feel like as an engineer, technical-wise, you are solid. Right now, room for improvement. So number one thing I can tell off the bat is your pacing, right? I believe you overcommunicated on the first question. Like, I feel like you got it. Like one example, you're good. Let's just, you know, you should just ask the interviewer, hey, like, this is my thought process. Boom. Let me just start coding it up. Boom, boom, boom. What do you think about this? Perfect. Now, can I, I'm just You don't have to ask me to run the test cases. Say, okay, I think everything looks good. I'm gonna start running the test cases. Is that okay with you? And I'll be like, yes, perfect.
Hurricane Automaton: And boom.
Stealthy Elephant: You don't have to go through like every line. Like you sure you can do like a one case, like line by line just to show that you understood it. I feel like you could definitely finish the question maybe like 8 minutes earlier. You already had that hash set process. You already had everything all to go, but But even though you, you already was correct, I feel like you would have been able to run it, but you were over-explaining it, right? Then sure, now you kind of were under pressure for the second one, even though you did solve it, right? Um, I want you to allocate more time for the second one, right? A lot of questions—
Hurricane Automaton: yeah, yeah, it makes sense—
Stealthy Elephant: a little easier question the first one, and you get a harder question the second one. So try to finish the first one as fast as possible, but in the most efficient way. Make sure it's correct. You, I think by halfway through, you already got it, right? But then you were explaining it and I was letting you, you know, I was letting you do your thing, but you just gotta go right into it after you get approval from the interviewer, right? So you were good, work on your pacing. Second question is, I mean, you were able to solve it, it's just I gave you a little bit of hint just because there's some time and I didn't want you to go into tunnel vision. So I would say is just be careful with your little syntax, little one-offs, right? Little things like that when you get to the infinite loop. And you're in a time crunch, sometimes you start panicking. So I don't want you to rush yourself. Yeah, just really be careful. Usually when you see an infinite loop, it's something with like— yeah, one, it's a one-off. It's like the most annoying thing. So just be wary of your counters, your plus plus, and make sure you're doing— but I think it's because you were in a little bit of a rush, you may have had some small issues, right?
Hurricane Automaton: It's all based on your timing, right?
Stealthy Elephant: Some other factors Some other feedback I have for you is, uh, maybe in the beginning, so you're asking questions of like the— they're trying to figure out the subsequences, right? Like you explained me the answer, but then you were still confused of the answer. So I was like, wait, oh yeah, explain it to me. So about the subarray, right? He said you were like, oh, I got it, it's really 1, 2, 3, 4. I'm like, oh, perfect, you understand it. But then you had some questions of like, oh, it's a subarray or not. So are you— were you trying to ask me if, like, if I just sort it, is that the answer? Is that what you're trying to ask me?
Hurricane Automaton: Yeah, that's, that's what I asked you. Like, say if I sorted, like, will I get the answer? Yeah. Like, yeah, right.
Stealthy Elephant: So were you just surprised? Oh, is it that easy?
Hurricane Automaton: So I have done that question. The thing is, I think it is worded a little differently. And, or maybe not, you know, like, maybe I got confused. Confused with the word called, like, you know, a sequence and like, you know, consecutive. I like, okay, is this the longest common subsequence kind of thing? So that's where I got confused.
Stealthy Elephant: So, uh, yeah, I see. So at that point, I think you should ask me, hey, is it a subarray? I think maybe that's what you're getting confused.
Hurricane Automaton: Yeah, yeah.
Stealthy Elephant: I think I know what you're talking about. For like dynamic programming, they usually ask for a subarray, so they have to be very right next to each other. So that's the— I think that's the little part you're confused. So The difference between consecutive sequence and subarray— subarray assumes that it's right next to each other and you can't just sort it like that. When I say sequence, it's a little bit easier by sequence because you can generally sort it with a, you know, quick sort and get it. Yeah. But why I want you to do is the most efficient one, which you exactly did, right? So maybe that was the hiccup, the difference between subarray versus consecutive sequence, right? So you got that out of the way. Uh, another thing is, let's see, let's see what you should do differently in the next interview is? I would say, I like how you keep asking questions. I like how you confirm, like, hey, can I go with this?
Hurricane Automaton: Right?
Stealthy Elephant: But I would like you to take a little bit more lead. You don't need to get my approval for everything. If you have good confidence, just be like, hey, I think this looks good to me. I'm gonna get started. Is that okay? I'll be like, yeah, sure. In terms of running test cases, you should just go into it right away. You don't have to ask for approval. Uh, I think you could definitely save some time. And that would be mainly it.
Hurricane Automaton: Mm-hmm. Makes sense. Makes sense.
Stealthy Elephant: Try to keep it as a— don't be afraid to ask for help, but you don't have to outright ask for it. You can kind of say, huh, I'm in this infinite loop. I feel like I'm super close. I'm just— I feel like I just have one small stuck one-off error. And you're kind of struggling through it until you just You kind of just say it out there. You're not asking for help directly. Kind of, you're kind of acknowledging the problem, and usually the interview will be, oh yeah, yeah, like, just take a quick look at this, right? So it's got— psychologically, it's not— you're not asking for— you're just stating where, which issue you're in. It's something that interviewers are super nice, right? They will just nudge you. In their head, it's like, oh yeah, I didn't really give hints. I just, you know, just— you're good. You, you do 100%. Um, so frame it like that. But let's just say the interviewer is terrible. They don't want to give you any type of help, and you're stuck. You should ask for it. Yeah, hey, I wanna— I'm stuck here. Do you mind giving me a little nudge? And that should be good.
Hurricane Automaton: Yeah, yeah, makes sense, makes sense.
Stealthy Elephant: Yeah, and then the last section is open notes, right? It seems like you're a very solid interviewer already. You're already applying to these companies. The best advice I can give you is keep going at it. It's— you have to do more questions that you're not the best test that, right? So what I used to do when I was applying for these tech companies, you do 3 questions a day, right? You do [REDACTED] 75, [REDACTED] 150, or whatever. If you're going for [REDACTED], you look at all the question banks, you do 3 to 4 questions a day, and, you know, if you're that good, you should be understanding the answer within 5 minutes, right? I'm not saying code it up in 5 minutes, but you understand which logic. As long as you have that logic and you trust your coding abilities, just move to the next question, right? Uh, then for this, once you get stuck at Put a deadline, right? Tell yourself, hey, I, you know, I maybe I had this issue, right? I would ask you to redo this question in 3 days, right?
Hurricane Automaton: Yeah.
Stealthy Elephant: And put a deadline like every— so 3 days later, you test yourself right now, pen and paper, right? Write the code out, see how fast you time it. Perfect. I had no problem. Okay, move on, move on to the next one. And you keep doing that. You keep regurgitating. And then let's just say 2 weeks later, you still haven't got like a 5, like a job yet, I would just do a recap, like a review of everything you've done and see the problems you keep messing up at. Right. I think you're good to the point where, you know, the trends, you know, the patterns, you've done every legal question there is, but once there's something that is a little bit of a twist, that's where you might get a problem.
Hurricane Automaton: Hmm. Yeah.
Stealthy Elephant: Yep. So yes, that is my feedback. Do you have any questions on all the feedback?
Hurricane Automaton: Uh, no, no. Uh, I, I think, yeah, I think pacing-wise. The thing is, you know, like meta interviews, they don't run the code. Like, and that's where like we need this manual run over of the code. Like, you know, like that, okay, hey, this is the edge case. Now other companies which run the code, they will want me to run the code. So maybe I should have asked that part that, hey, do you like, you know, what kind of test like do you expect me to run? If it is run, I think the best tool, like I think I utilize that in the second question rather than running it like, you know, verbally, like which would have been like pain, like, you know, uh, really painful, like, you know, and like impossible, to be honest. Uh, I think, uh, it's better that I, I, we, we did run the test case like this.
Stealthy Elephant: Yeah, exactly. So yeah, I like that. So yeah, I think you're good. I think just, I think just if I were to TL;DR it, is your pacing just needs to get work. Yeah, that's, that's, I guess that's your biggest thing, right? Just fit you. It seems like you're in, you what the question is going to be. Figure out the answer as soon as possible so you have time for the second one. And if you finish the question early, perfect. Don't leave the interview early, just be like, oh yeah, I have a lot of questions for the company, and then you treat it as like a little friendly, yeah, casual conversation. Because at the end of the day, if you can solve the question and the person likes you, trust me, they will vouch for you. I agree. I've had many, I had many situations where like I help a lot of people, like I coach them for their specific companies. And just if you finish your question early and you, you know, you have 5, 10 minutes just, you know, paying the shit, just talking to them about, you know, just their company and everything. They will definitely upvote you a lot more. They will, like, sometimes you can get even higher bump raise or base salary raise just because the way you're interacting and they like you. They see that you are more of a senior role. They see that you get along and you bring that to the table.
Hurricane Automaton: Okay, makes sense, makes sense. Yeah, uh, okay, I appreciate it.
Stealthy Elephant: I apologize for the technical difficulties at the very beginning, but I hope you got through it.
Hurricane Automaton: All good. I really appreciate you taking so much time, like, you know, and working with me on this and like all the detailed feedback. I really appreciate it. Yeah, perfect. All right, thank you so much.
Stealthy Elephant: I will share my contact details if you want to ask more questions. Feel free to email me, but other than that, thanks so much, Hurricane. All right. See ya, man. Take care. Bye-bye. All right. Bye-bye.