Java Interview with a FAANG engineer.

We helped write the sequel to "Cracking the Coding Interview". Read 9 chapters for free

Longest Consecutive Sequence + Cliff Trees

Watch someone solve the the problem: longest consecutive sequence + cliff trees problem in an interview with a FAANG engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.

Longest Consecutive Sequence + Cliff Trees: Java Interview with a FAANG Engineer - YouTube

Interview Summary

Problem type

The Problem: Longest Consecutive Sequence + Cliff Trees

Interview question

Problem 1 — Longest Consecutive Sequence: Given an unsorted array of integers, return the length of the longest consecutive sequence of elements. The optimal solution runs in O(n) time using a HashSet to identify sequence start points and extend each sequence without redundant work. Problem 2 — Cliff Trees: Given an n×m binary grid representing a cliff landscape (1 = tree, 0 = empty), and a coordinate (r, c) to cut, determine which trees remain after the cut. A tree is "stable" only if it is connected through adjacent trees (up/down/left/right) to at least one tree in the bottom row. Any tree no longer meeting that condition after the cut disappears (becomes 0). The solution uses DFS seeded from the bottom row to mark stable trees, then zeroes out anything unvisited.

Interview Feedback

Feedback about Analog Ibex (the interviewee)

Advance this person to the next round?
Yes
How were their technical skills?
3/4
How was their problem solving ability?
3/4
What about their communication ability?
4/4
# Mock Interview Feedback ## 1. Strengths You communicated clearly throughout the interview and had no major issues explaining your thought process. Your delivery was confident, especially on questions where you understood the approach well. You did a good job walking through your logic and keeping the interviewer aware of what you were thinking. Overall, this was a solid performance for a **mid-level role**. You showed that you can problem-solve, communicate, and work through the solution in a structured way. --- ## 2. Areas for Improvement The biggest area to improve is your speed and efficiency when walking through test cases. Once you walk through the first test case line by line and confirm that your logic works, you do not need to repeat that same level of detail for the second and third test cases. Instead, use the first test case to validate the core logic, then run the remaining test cases more quickly together. A better structure would be: 1. Walk through the first test case line by line. 2. Confirm the logic works. 3. Mention the other test cases you want to validate. 4. Run them together at a higher level. You should also be more proactive about edge cases. Do not wait for the interviewer to ask. After walking through your test cases, immediately say something like: > “Here are the edge cases I’m thinking about.” Then list them clearly. Another area to improve is avoiding negative self-talk. Try not to say things like: > “I don’t think this is going to work.” Even if you are unsure, frame it around the logic instead: > “This edge case might cause an issue, so let me think through it.” That sounds more composed and gives the interviewer confidence that you are debugging thoughtfully rather than doubting yourself. You should also be especially careful with boundary check bugs. When something goes wrong, your first instinct should be to ask: > “Is this a boundary issue?” A lot of bugs in interviews come from off-by-one errors, index bounds, empty inputs, or start/end conditions. Make boundary checks one of the first things you verify when debugging. --- ## 3. What to Do Differently in the Next Interview For the next interview, own the structure more proactively. Use this flow: 1. Walk through one test case line by line. 2. Get confirmation that the logic makes sense. 3. List the remaining test cases. 4. List the edge cases. 5. Run the test cases together at a higher level. 6. State the time and space complexity without waiting to be asked. You should also treat the interview more like a collaborative conversation. Bring the interviewer into your thought process by checking in at key moments. For example, you can say: > “I’m thinking of validating the main case first, then checking edge cases around empty input, single element input, and boundary conditions. Does that sound reasonable?” This makes the interviewer feel involved and gives them a chance to redirect you if needed. Also, be proactive about complexity. After explaining your solution, say: > “The time complexity would be ___ because ___. The space complexity would be ___ because ___.” Do not wait for the interviewer to ask. At senior levels, they expect you to cover that naturally. --- ## 4. Open Notes This was a solid mid-level performance, and you are close to senior-level execution. The difference is that senior-level candidates own the full interview format without needing to be prompted. That means moving through the process on autopilot: 1. Clarify the problem. 2. Explain the approach. 3. Walk through a test case. 4. Cover edge cases. 5. State time and space complexity. 6. Debug calmly if something goes wrong. At the senior level, the interviewer should not have to pull these things out of you. You should lead the structure yourself. One important note: stay decisive. Avoid saying anything that gives the interviewer a reason to doubt your confidence. You do not need to pretend you know everything, but you should sound composed and logical even when you are unsure. Instead of saying: > “I don’t think this works.” Say: > “There may be an issue with this case, so I’m going to trace it carefully.” That sounds much stronger. Overall, you are in a good spot. The next step is tightening the interview structure, moving faster through validation, proactively covering edge cases, and sounding more decisive while debugging.

Feedback about Stealthy Elephant (the interviewer)

Would you want to work with this person?
Yes
How excited would you be to work with them?
4/4
How good were the questions?
4/4
How helpful was your interviewer in guiding you to the solution(s)?
4/4

Interview Transcript

Analog Ibex: Hello! Hey, how's it going?
Stealthy Elephant: Doing great, doing great. Yeah, so my name is [REDACTED]. I will be your mock interviewer today, and the way I usually structure these is first 3 minutes will be a brief introduction of each other, experiences, where you're currently in the interview process, The next 45 minutes will be 2 technical questions, and the last section, 5 to 10 minutes, will be the feedback section. Do you have any questions?
Analog Ibex: No, no, I'm good.
Stealthy Elephant: Okay, yeah, so my name is [REDACTED]. I've been working— I worked as a data engineer at Atlassian for the past 6 years, and—
Analog Ibex: Hello? I think I can't hear you anymore. Hello? Hello? Yep, can hear you now.
Stealthy Elephant: Okay, yeah, so I've been at Atlassian as a data engineer for the past 6 years. I work with a multitude of microservices. I also host system design, data engineering, so, um, regular data structure, Mock Interview questions. So I've been doing that for the past few years now. Can you tell me a little bit more about yourself?
Analog Ibex: Yeah, sure. Uh, so I'm [REDACTED]. I'm, uh, currently at [REDACTED], uh, as an L5. So So before that I was at [REDACTED]. So [REDACTED], I'm on like the [REDACTED] or like [REDACTED] manufacturing team. So we essentially like build software to support like the manufacturing of the [REDACTED] satellites. So it's very interesting problems, a lot of security and like different domain space. So yeah, and I'm currently interviewing with [REDACTED]. So I have the phone screen tomorrow and then I have a [REDACTED] on-site next Wednesday. So yeah, just wanted to prep, like, I guess the— and both of those roles I'm targeting mid-level. So yeah, I'm just— just wanted to prepare, like, the coding problems for those styles, yeah.
Stealthy Elephant: Okay, nice, nice. And then just wanna make sure, are you doing for a senior engineer, mid-level?
Analog Ibex: So mid-level, so L4 for— [REDACTED] and mid-level for [REDACTED]. Yeah, perfect, perfect, perfect. Okay, so great.
Stealthy Elephant: If that's the case, let's get started. Do you have any other questions before we go ahead?
Analog Ibex: Uh, no, no questions. Perfect.
Stealthy Elephant: Okay, got it. I'm gonna be— which, which coding language will be coding in today? Java. Java. Okay, got it. Okay. Okay, I'm gonna copy and paste it right here. Okay, from line 10 to 28, feel free to go ahead.
Analog Ibex: Okay, given an unsorted array of integer nums, return the length of the longest consecutive sequence. Consecutive elements sequence. Okay, so for this question, I think for this we want to essentially— so we can do this problem in O time complexity solution. So we can also have space complexity of O, but we have to use a hash set. So essentially we just do a first-pass run of all the elements in this unsorted array and then store it in the hash set. Um, so I guess a little bit of clarifying. So the constraints, I guess, um, yeah, so I guess for constraints, like, we're always going to have— like, you're not going to have like an empty or like like malformed inputs in this like integer array, it's just always going to be guaranteed that like the, I guess, edge case is like our input is always going to be an array of numbers, correct?
Stealthy Elephant: Correct.
Analog Ibex: Yeah, okay, so then we can use the hash set approach. So we can do a first pass run of just storing all the numbers that we've seen in the hash set. And then, um, iterating through like those elements in the hash set, and then we check, um, is it the start of a sequence. So, right, yeah, like because this is kind of the approach that we're looking for, right? Uh, like we check if the number, um, doesn't have a number before it. So if it's like 100, there's no 99 in the set, Right. And then you want to try and find like 101 and 102, correct? Is that, is that the kind of approach that we're looking for?
Stealthy Elephant: I like that.
Analog Ibex: Well, for, uh, so for nums in the first example, the answer would just be 1, 2, 3, 4 because that's like the consecutive sequence. And then, um, yeah, the second example would be like 0, 1, 2, and then so on and so forth. Does that sound like a good solution to kind of—
Stealthy Elephant: Yeah, I like it.
Analog Ibex: Enough to go ahead and code up?
Stealthy Elephant: Yeah, sounds good to me, yeah.
Analog Ibex: Yep, so I can go ahead and code that up. So, just start with a public method where our output will be an integer. And then, I guess we'll call this longest consecutive sequence. Our input is an integer array called nums. And I said, like I said before, we're going to utilize a HashSet data structure to allow us to have O time complexity. So, install Integers here. And then, so we want to do a first pass run of all the elements in the array and just store it in a number set. So, yeah. So, there are— there are going to be duplicate elements, but that's fine because essentially it would just overwrite each other because it's a HashSet. So, that's fine. And then, I guess we also want to initialize the length. Okay, so what we want to do is iterate through each, so we have to do another pass through of the elements in the hash set.
Stealthy Elephant: So current_set.
Analog Ibex: Okay. So, we have to check is— so, we can do a while loop essentially or— sorry, not a while loop. Do an if statement, if clause. So, is this current number a start of a sequence? Um, because we don't, we don't necessarily need to check. So like, for an example, like the first one, 1, 2, 3, 4, like we don't have to check from like 2 on because that's just like repeated work. So like we just want to find like a start of sequence, right? So, um, we have to check number_set.contains, does not contain current minus 1. Then we can start check— that means to start the sequence. So then we can initialize a current sequence length, so guaranteed to be 1. So then we can go into a while loop and just keep iterating current until we don't— we can't find another number in number_set. So yeah, so you can do while current— let's start while number_set.contains current++. And then we can also increment the length as well. So, every time we find the next number within the sequence, then correspondingly increment the sequence length. And then, and then we can check the length. So, we kind of have to do a max comparator because there could be multiple sequences that we encounter in this set. So we want to check, is it the max length, um, of like all possible sequences that we— consecutive sequences that we find? Okay, then we just return— you can just return length. I can run through this example. I can run through this code with some test cases to kind of walk through it. That's fine.
Stealthy Elephant: Yeah, let's do it. Okay, cool.
Analog Ibex: Yeah, so first example, we're gonna have 100, 4, and 200, 1, 3, 2. So, we have a HashSet. We're gonna, of course, iterate through it and then, of course, insert the same numbers. 1, 3, 2. And then we're going to start iterating through each number in number_set. So, 100, um, this is in length equals 0 currently. So, 100 is a start of a length. So, then, um, but there's no 101. So, then length just becomes 1. And then we go to 4. And then that's still one— that's not a start of a sequence, so we'll just skip that number. 200 is also a start of a sequence, so we'll skip that number. Well, it's still going to be 1, but there's no 201, so max length is still 1. But once we encounter 1, that's when we get into the while loop, and then current sequence length just traverses through a number set to 1, 2, 3, 4, and then we eventually get the 4 to get the answer here. Do you want me to run through another example, or is that good enough?
Stealthy Elephant: Sorry, I was muted. Yes, you can run through the test cases.
Analog Ibex: Yeah, all the test cases. Okay. Yep. Um, uh, 0, 3, 7, 2, 5, 6. Okay. So, again, the set, I guess the same thing. So, then length 0 first. So, when we get to 0, it's the start of an— it is the start of a new sequence because we don't have -1 in here. So, then we get into the while loop and then we eventually encounter 0, 1, 2, 3, 4, 5, 6, I guess this whole thing, 8. So then, yeah, it gets to our answer of 9, and essentially every other number would just be skipped because, um, because of this, uh, if statement, because every other number does have a preceding number before it. Then the answer would just be 9. Then the last, third test case, the last one, 0, 1, 2. So again, it'll skip 1 because there's a 0. And then it gets to 0 and then find the 0, 1, and 2. And yeah, it'll get to length 3.
Stealthy Elephant: Yeah, sure. Do you mind running it in the code?
Analog Ibex: Yeah, can run it. Sure, so can do that. So can create some integer nums here. Okay, so probably have to make this static so I can actually call it in the static method. K, then I'll just print, um, sequence 1. Uh, what's that? Oh, is it because I didn't— this should work now. Um, no, I have mainnet. Maybe I—
Stealthy Elephant: line 32?
Analog Ibex: Implicitly declare class must have main method. Oh, okay. Oh, okay, I see. Yes. I just need to put it in this solution class. Okay, so that should work. Ah, some spacing. Let me see. Let's put newlines so it's better formatted. Okay, so it's off by one. So, Something— okay, so I think there's an edge case here. So I think if I just maybe have this at 0, it's probably fine.
Stealthy Elephant: Yeah.
Analog Ibex: I think it's because— oh, okay, I think I see what's going on. Okay, yeah, so I think there's a just the edge case where I was just incrementing it an additional by 1. So, yeah.
Stealthy Elephant: Yeah, then what are some other small edge cases you may need to handle?
Analog Ibex: Uh, additional edge cases, you mean?
Stealthy Elephant: Yeah, anything else?
Analog Ibex: Um, so I guess negative numbers can handle fine. Like, like the possible minimum to like maximum integer like bounds, I guess that's also handled fine. Yeah, because the constraints like, because it goes to like 10, negative 10 to the 9th and 10 to the 9th, so like big integers are also handled fine. In terms of like if there's like malformed inputs, like if there's potential null values in an index or not an integer, then that's not handled. But I guess in this scope of this problem, it's all guaranteed to be integer numbers. So I guess that's fine. So is there any other edge cases that you were particularly trying to look for?
Stealthy Elephant: So, yeah, it's an empty list or just one value, right? Those are the main two looking for.
Analog Ibex: Yeah, okay, empty list. So, if there's an empty list, then, um, it would just return 0, uh, because essentially it would just skip these for loops and then just have length of 0 just be returned. Um, what was the other edge case that you're talking about?
Stealthy Elephant: If you just have one item.
Analog Ibex: One item, okay, yeah, one item. So, yeah, I actually think one item might be wrong in this case. Let me test that out. Yeah. Because, yeah, let me just kind of explain that first. So, yeah, there's just like one. Oh, okay, so that's right. Yeah, yeah.
Stealthy Elephant: So quick advice: don't, don't tell— don't put yourself down. Don't say, oh, this is going to be wrong.
Analog Ibex: Oh yeah, well, because I was a little confused initially why like it had to be zeros. I was like, oh, like, okay, yeah, yeah, maybe I'll do it again.
Stealthy Elephant: Yeah, for sure. Even when you're trying to show it, don't say that to an interviewer because then they're gonna think, yeah, they're gonna think, right? Because I'm reading it, I like, I know for sure it'll work, but then you kind of just shot yourself in the foot by saying, oh no, I don't think it's gonna work. And you're, you're like, oh wait, it does work, right? So please don't say that. Just like, okay, I go through it. Even if you're hesitant, just run it In your head it works like, oh, perfect, right? And then you just explain why it works, right? Don't shoot yourself in the foot. Don't like— yeah, so we can move. Uh, where is your time and space complexity for this question?
Analog Ibex: Yeah, so our time complexity is going to be O, uh, because we essentially do one pass through of the initial input array, which is going to be n, and then we do another pass through of the number set, which at worst is of course going to be n. So it's going to be 2n, so it just averages out to O. Space complexity is O because we can at worst store, like in the second example, we stored all numbers of the size of the, of the input array. So yeah, it's also O for space.
Stealthy Elephant: Okay, nice. All right, everything looks good. We can move on to the next question.
Analog Ibex: Okay, sure, sounds good.
Stealthy Elephant: Okay, yeah, so here is the question. I'm gonna give— as you read, I'm gonna give you the actual example, okay?
Analog Ibex: Sure. Working on a verb, okay. So cliff is modeled as a 2D grid. Okay. Yep. Yep. 2D grid. So then you have ones and zeros where you have a tree is one and then empty rock is zero.
Stealthy Elephant: Okay.
Analog Ibex: The bottom row is going to be solid ground. The two trees are connected if they are adjacent up, down, left, or right. Four directional. Okay. Okay, yeah. A tree is considered stable if it is connected through other trees to at least one tree in the bottom row. If a row— tree is not connected to any tree in the bottom row, it will fall off the cliff and disappear. Okay, so you have an n by n grid landscape of zeros and ones and a coordinate, um, type of r and c representing the tree you cut down. Okay, uh, cutting this tree means the cells r and c become zero first.
Stealthy Elephant: Okay.
Analog Ibex: And then after that, any trees are no longer stable, so no path of 1s to the bottom. Okay, I see. So essentially, I guess, okay, I see. So from what I'm reading, the stableness is kind of like the key of this problem where essentially they're gonna be connected through other trees, yeah. So at least one tree in the bottom row. So I guess let me kind of read it more to kind of before I ask my question. So to at least one tree. Okay, okay, I see. Yeah, so it has to— so I see, I see. So the tree has to at least be within the same, like, adjacent— so essentially it's kind of like an island, right? So the tree is to, um, be within an island that has to be in the bottom row, right? So that's considered a stable tree. Um, yeah, so I guess the question would be, would the landscape that we're given we would never have a tree that's unstable, correct? Like we wouldn't have just like a tree that's like floating?
Stealthy Elephant: No, so you can assume that the input that you're given is a valid tree.
Analog Ibex: Is a valid tree, okay, yep, sounds good. Yeah, 'cause I wasn't sure if we would be given like floating trees or something. Okay, so, yeah, so in this example, I guess, Yeah, all the trees are really just connected by the tree, the row, the last row here and like, yep, at this tree. Okay, so then we wanna make a cut at 1, 3. So essentially, yeah, row 1 and column 3, okay. Yeah, so we wanna make a cut here. So this would be like 0 here. Okay, I see. Center stable, it is connected to string 0 first. So any trees that are no longer stable will also fall and become 0. Okay, I see. So in this case, so essentially we want to cut this to 0, and then I guess explore the other neighbors, and then see if— and then maybe traverse. Okay, so, so we want to cut this here. So essentially, after cutting this, everything here becomes 0. Oh wait, sorry, let me, let me type in a new Sure, no problem. Yeah, let me type in a new so I can maybe illustrate it better. So this is the regular input, right? So we make this cut at , and essentially from what I understand of this problem, like, all of these are deemed unstable, so they just fall over. So We just basically want to change the input to this, correct? Is that the answer? Is that kind of like what we're looking for? Wait, give me one sec.
Stealthy Elephant: So I'm looking at input. You are saying, is this the output you think it would be?
Analog Ibex: Yeah, this is the desired output that we want, right?
Stealthy Elephant: Not exactly, right? So let's go through line 33-36, right? So let's remove— let's get the cut at 1, 3. Let's do that first. Yep. So can you remove it on line 33-36?
Analog Ibex: Yeah, it's right here, right? So just right here.
Stealthy Elephant: No, no, it would be— so 0, 1, 2, 3, right?
Analog Ibex: Oh, sorry, sorry. Column 3. Okay, sorry. Yeah. So yeah, right here.
Stealthy Elephant: So now what would your answer be based on that?
Analog Ibex: Ah, okay, yeah. So yeah, let me, let me just recopy this over. Yeah, okay, I miscounted because for some reason I just counted. Yeah, just, I literally just went 1, 2, 3. Okay, so right here, and then so essentially, um, you basically want to just chop all these off because they're, they're their own like Essentially island, right? So like these all still all of these ones are connected to the bottom row. They're still connected to the bottom row.
Stealthy Elephant: Um, yeah, so let me see too. Yeah, that looks good. Perfect. You got that. And let me give you one more example to make sure you got it. So, uh, there is that. Let's give you another one. Now what would happen if we have it— okay, what would be the output for line 54 to 60?
Analog Ibex: So we chop this one off again. So they're still stable because they're both connected to the bottom row. So nothing changes after we chop it off. So from, uh, so from my implementation, I guess first we would make the cut in the input and then we'll just traverse through, um, like all the elements like one by one within the row. And then, um, every time we encounter a 1, we'll probably just traverse the whole kind of tree and then try to see if we can get to the bottom row. And if we get to the bottom row, I guess we can have a boolean flag maybe. Yeah, we can have a boolean flag. Or actually, what we can do is actually just literally just start at the bottom row And then if we encounter any trees, then just traverse the tree, um, and then mark them as visited. Um, and then after we mark them as visited, that means they're safe, right? They're safe from being like falling off or like whatever. And then, um, the ones that aren't connected to a tree at the bottom, they're still going to be marked as 1. So we'll make another traversal of all the elements, make another scan of all the elements from top to bottom, and if they're still like unvisited and they're 1, then we can just mark them as 0. Like a good approach, or do you think you want more of a time— better time complexity solution?
Stealthy Elephant: So, so it seems like— so where are you exactly starting from? What would be your start point?
Analog Ibex: Yeah, so the start point would be at ba row 3, or like the bottom row.
Stealthy Elephant: Yeah, and then it's just like you were doing, and then what type of approach are you doing?
Analog Ibex: So we basically just try and find a 1 at the bottom row, and it tells us that there's a tree. So then we want to traverse that tree and mark all the 1s as safe.
Stealthy Elephant: Got it. So are you doing DFS?
Analog Ibex: DFS, yes, DFS, yes.
Stealthy Elephant: And yeah, I mean, everything looks good to me. Yeah, so you start from the bottom row, you do DFS, find the 1s. Yeah, sounds good.
Analog Ibex: Yep, okay, sounds good. Let me code that up. Probably try and code it up in 10 minutes. We have some time.
Stealthy Elephant: No, you have, uh, you technically have 20 minutes.
Analog Ibex: 20 minutes, okay, yeah, yeah, yeah, I'm good. Okay, so, um, can probably just start again here. A lake. So yeah, we want to return this upstream leaves. The input is just another 2D array. Or we call it landscape again. Landscape. Okay, and we're also given a cut input, right? So it's just like a, like a, Does it matter if it's like an array of size 2, or if we can just do cut x and cut y?
Stealthy Elephant: No, it's— the input's going to be more like—
Analog Ibex: Like an integer? A tuple.
Stealthy Elephant: A tuple, yeah. A tuple or an array. Like a 2 array. Yeah.
Analog Ibex: Just do array. This one. Yeah, yeah. Okay, so we want to make a cut, so we'll just do landscape cut 0, cut 1, 0. Yep, and then like I said, we want to traverse through the bottom row. So, we also wanna have, I guess, a visited array. Yeah, so, boolean visited. So, I'll just make it scope because I'm gonna need a DFS helper function for this too. So, visited is also going to be the same size as landscape, landscape length, and then landscape column length. Okay, so we're going to traverse through the bottom row now. So, I'm going to take equals 0 and landscape. I is less than landscape column length.
Stealthy Elephant: Oops.
Analog Ibex: So, then we want to check if landscape and then landscape.length minus 1. So, the last row, the bottom row, and then i, if it equals 1, that means there's a tree. And we also want to see if it's visited too, right? Because we don't want to We don't want to be traversing the same tree too. And it's not visited. Same, same thing here. Okay, so if we encounter a 1 and it's not visited, so we encounter a basically a tree trunk at the ground and then it's not visited, that means we need to traverse it. So then we'll call DFS, and that's where I guess I'll start coding up the DFS method. DFS. So we want our landscape, of course, and then we want our current coordinates, so x and y. I think that should be it for now. So we want to have our edge case for DFS because it's recursive. So we want to know when to actually break out of this DFS loop so it prevents infinite loop. So just the bounds checking. So if it's less than 0, for x, I guess is like the landscape.length. So this will tell us that, you know, we're out of bounds. Y less than 0 or yscape.length. And yeah, we can also do the x check or the 0 check too. So, landscape. So if it's not a tree, it's not part of the tree, then we can just return. Okay. So once we're here, so I can actually just populate these fields now. So landscape.length minus 1, And then i, okay. So, once we're here, we can mark it as visited. So, we don't want to, yeah, we can just mark it as visited in a separate array. x, y equals true. And then, oh, and we also have to check if it's visited. Yeah, because, It would also, where since we're not, 'cause normally I guess in like an island traversal we would mark it as 0, but in this case we're not 'cause we want to preserve that input. So yeah, and if it's visited already then return. So now you want to mark it as visited and then traverse the neighbors. So the DFS landscape. So traverse left, traverse right, and then up and down. Okay. Um. And so that should be it for the DFS traversal. So yeah, so we've explored all the trees so far. That means that we should have marked all the trees that are stable to be stable. And then now we just have to do another scan again of the landscape to make— to mark the the ones that aren't visited as 0. So do another scan here. And so if landscape i, j equals 1 and visited— so it's not been visited— then update it to 0. Okay. Then we can just return the landscape. Mm-hmm. Cannot convert int to boolean. Oh, sorry. Okay, yep. So, I mean, I already kind of ran through the test case, I guess, kind of explaining my approach. Maybe I can just try running it.
Stealthy Elephant: Yeah, yeah, let's try running it. And let me see if I can give you Give me one second. Yes, start setting up the test cases. I'm gonna give you the— sorry, not the test, the function. I'll give you the exact example so you don't have to put the commas. Sure, I'll do that.
Analog Ibex: Yep, sure, sounds good.
Stealthy Elephant: Okay, all right, gonna copy paste it here.
Analog Ibex: Uh, in the main method?
Stealthy Elephant: Yeah, yes, here you go. Where is your, uh, where is your thing?
Analog Ibex: Should be line 100, the main method.
Stealthy Elephant: Yeah, yeah, I see it, I see it. Here you go. So, let's see, let's— I'll do landscape 1 and I'll give you another one for landscape 2. Okay, feel free to go ahead.
Analog Ibex: Okay, thank you.
Stealthy Elephant: And then the cut will be, you know, the 1,3.
Analog Ibex: I can just define the cost. Cannot define dimension.
Stealthy Elephant: OK.
Analog Ibex: I know that. OK. You want to— Cut trees and then landscape one, cut. Okay, and, uh, should I just print it out, or—
Stealthy Elephant: Yeah.
Analog Ibex: I guess I'll just print a new line here. —stack overflow.
Stealthy Elephant: Sorry, what did you say?
Analog Ibex: I said I got a stack overflow at 93. Yep.
Stealthy Elephant: So it seems like there is either a balance issue, overflow, or a receipt.
Analog Ibex: OK. Yeah, so it might be— It might be because of my recursion.
Stealthy Elephant: Let me see.
Analog Ibex: x is less than 0, landscape, x equals landscape, 0, true. Hmm. Looks right. Okay, so the bounds checking— is it because it's static? I don't think so. I don't think it's because it's static.
Stealthy Elephant: Yes, I would like you to, maybe I'll just give you one hint. I want you to look at your if statements, your boundaries.
Analog Ibex: Yeah, so yeah, if it's, so if x is less than 0, then that's out of bounds because it goes from 0 to landscape length. Because 0 to landscape length minus 1 is the valid boundaries for x, and then y and y column length is also valid boundaries. X and y for x equals 0. So we also want to return there and visited . Then return. Looks right. I mean, is it— you're talking about line 89 in this if statement?
Stealthy Elephant: Yeah, so let me make sure I'm even looking at it correctly. So I'm looking at— Yes, so, okay, so I'm looking at the parentheses, right? I just want to make sure your parentheses are proper. Okay, so you have x less than 0, okay, x equals equal landscape.length, boom, boom, boom. Okay, y equals the landscape, just looking. So I, okay, y, uh, length. No. Okay, because I know— I would say, I would say maybe look at your ants and horse.
Analog Ibex: Oh, oh my God. Yep, that'll do it. Okay, thank you.
Stealthy Elephant: Yep. Let's see, where is that now? Perfect. Boom. Uh, okay, let me see. Can you, can you do like a new line?
Analog Ibex: I probably need to do a new line here.
Stealthy Elephant: Let me just remove this part. Remove that part for you. Okay.
Analog Ibex: Oh, did not do a new line. Still no new line? Okay. That's okay, let me see.
Stealthy Elephant: All right, let me just— 0011, okay. 0, 1, 1. Okay, it looks good. That one looks good. And this one also looks— yeah, yeah, it looks good.
Analog Ibex: Awesome, thank you.
Stealthy Elephant: Yeah. What is the time and space complexity? Uh, yeah, time complexity.
Analog Ibex: So for DFS, um, uh, I guess it would be The complexity would be O because we're basically traversing through like all the like rows and this is like so n is like the length of the rows and then m is the length of the columns. And since we're marking them as visited, I guess we're like at worst like visiting them like, like 1 or 2 more times, I guess.
Stealthy Elephant: You said time complexity is O ? Yeah. Got it. So it would be, so if you think, if we look into it, right? You said that It would be, you know, you would want to make sure that you're looping through everything, correct? Yeah. Right. I wouldn't say it's O , it would be O .
Analog Ibex: n × m, yeah, n × m.
Stealthy Elephant: Yeah. Yeah. Okay. Yeah. So because you're iterating— and what would be the space complexity?
Analog Ibex: Space complexity would be O . O . I think it's the same thing because we have a boolean visited array that we have to store, so that's some extra space that we need to allocate.
Stealthy Elephant: Got it, but I just want to make sure, do you understand? So the reason why it's O is because your cut trees, right, it iterates over the entire grid once. Yeah, yeah, yeah, yeah, right. And then when you do the DFS, you visit each cell at most once. Right, so that even though there's two nested for loops on like line 70 to 83, it still iterates the full grid.
Analog Ibex: Yeah, so it's kind of like an area, right? Like kind of like to think of it as like an area formula. Like, yes, the length of the row times the length of the columns.
Stealthy Elephant: Yes, correct, correct. Yeah, so okay, perfect. And then is there any other edge cases that you, you would, you should be able to handle? What are some things that can mess up your code? Or it might not, or something that you should—
Analog Ibex: So I think like an edge case would be like all zeros or like all ones. And in terms of all zeros, like if I don't think it would— the cut wouldn't mess it up because it would just kind of update as zero and nothing would change. And basically, as we're traversing through the bottom row, it won't enter DFS at all if it's zeros. And if it's all ones, then it would enter DFS and mark the whole, like, grid as visited. And then, um, not— yeah, it would basically mark the whole grid as visited even after we cut like a single point in the, in the grid. So then that would also handle that case as well. So yeah.
Stealthy Elephant: Okay, sounds good. Let's wrap it up and I'll go over the feedback section. Cool. Perfect, perfect. So yeah, so the way I usually break down this feedback is one, areas of strength, number two, room for improvement, number three, what you should do differently in the next interview, and number open notes. So number 1, your strength is you're able to get the gist of the question, you're able to communicate pretty well, you had no issues going through, and I think you were able to do just fine. You said you're going for the mid-level role, correct? Yes. So it seems like you're very solid for a mid-level role, and it seems like you're very confident. Like, even for the first question, you know exactly what to do, right? You don't have issues, right? So in terms of improvement though, For number 1, I feel like you could have done it faster, right? You don't have to over-explain every single test case. So what I would say is as soon as you went through the first test case line by line, that's okay, right? You don't have to go to the second test case line by line, you don't have to go to the third test case line by line. As soon as you figure out the first one, just run the code, right? Test cases 1, 2, 3. And also while you're about to run the 3, like after you run it, then be like your next method should be, okay, let me figure out what edge cases I have, right? Without me kind of hinting you at it., right? So I want you to be more proactive about that. Yeah. You go through one test case, go line by line, looks good, you get the confirmation from your interviewer, then you do the whole, okay, here are test cases, runs, here are some other edge cases I can think of. Boom, you solve that, then you kind of like jumping the gun of saying, hey, here are the steps and you seem more confident, right? And then, and by the way, since I got the edge cases, here is the time and space complexity, right? So boom, boom, boom. You solve the question, you answer it, you get your edge cases done, then you say here's the time and space complexity, right? And you save so much time without waiting for the interviewer to give you that approach. And number 2 is, like I said, even if you're not sure about the answer, don't say I don't think it's gonna work, right? Just be logical about it, being like hey, this is the edge case I would say, right? So I think for the edge cases, kind of give a little push, like, hey, where are the edge cases? And then I think there's no— nothing in the set— I'm sorry, nothing in the array, or one in the array. Just think of any possible ideas, right? Because they always look for edge cases. So just be a little bit more proactive about that, and don't say, I don't think it's going to work. So go line by line, and if it works, perfect. If it doesn't, then you just start explaining, hmm, okay, there seems to be an issue in the code. And I also know you haven't gotten really bogged down, but if it comes to that point, feel free to ask for help, right? Yeah. You can always get confirmation like, hey, does this sound good? Am I going in the right direction? You did do that, but just in case, just be aware of that because I want you to treat it as a regular conversation, right? Yes, it is an interview, but the interviewer is there to really just vibe with you, right, to vibe code with you, to make sure you're on the right path. Unless you get a bad interviewer, they might not say anything at all, but even at that case, you have to communicate, right? You have to kind of get them involved, put them on their toes, make sure that they're involved. So at the end of the day, you solve it, right? That's number one thing, you gotta solve it, but you also gotta make them feel like, wow, you can work with them. Yeah. And then second question, I think everything was really solid. I think you just had that little hiccup, right? So it's not a big deal, just be careful with that because something like that when you get a memory error, you might get into a rabbit hole. You might, oh my God, I can't. But you saw how small the fix was, right? So I usually think to myself, is there any recursive issue, right? This is usually what, 95% of the time it's a boundary thing. There's something I've done, maybe extra parentheses, the and or. So just be careful with that. What else, what else? I think that is basically it. Seems like you were pretty solid. In terms of things you should do differently, all right, just, you know, don't shoot yourself in the foot. Don't say like you're not— it's not gonna work. Number 2, um, be careful with the boundary checks. That is basically it. I think you're pretty solid for mid-level. And let's see, open notes. Open notes is— I, I mean, how long have you been interview prepping for or studying?
Analog Ibex: I mean, I've been doing this for a while in terms of like, but like I guess like I kind of took a break for like 6 months, so I've just taken it back up like 2 months ago. But I've been doing this for like the past 2 years, I think. Like, yeah, so like, and I got out just switching again, like trying to interview again. So like now I'm just trying to get the rust off. But I mean, I, so, so in terms of like, I guess I had a question about running the code. So I know like with [REDACTED], especially, we, like, they don't like—
Stealthy Elephant: Oh yeah, they don't want to offer it.
Analog Ibex: They just don't. Do you think, like, so like that's why I wanted to maybe try to over-explain the test cases. Do you think that was too much? So like maybe just like one test case would be fine.
Stealthy Elephant: Don't over-explain test cases either because I think from the first case you were good, right? There's no need to explain the second and third one. And do you explain it if the interviewer tells you to? Right? You can just say, hey, this is the first case, I think it's best bet. Then maybe you can go over the edge cases line by line, right? Yeah. And then on the [REDACTED] interview, you have the [REDACTED] Doc, you go through it, you get— you see, you see the face of the interviewer, so you kind of understand their body language, their facial expression. And then you see, hey, like, you know, I'm able to— do you also want me to do these other cases? I feel like it, you know, I covered the first test case, I've covered these two edge cases. And they'll be like, yeah, this is perfect, you can move on, rather than you over-explaining and they're just watching you, then you're wasting time.
Analog Ibex: Yeah, yeah, right, makes sense. So like, kind of maybe like if they prompt me, then I'll go forward, but like don't try to like, yeah, overcompensate, I guess.
Stealthy Elephant: Okay, exactly, exactly, exactly, yes. So yeah, any other question? Oh, sorry, so the open notes part I was gonna give you, I know you've done it for 2 years, but this I always suggest anyways, like, you know, if there are still more questions to be done, right, of course you have the [REDACTED] 150. But dude, I always do 3 questions per day, right? But if you're at that point of you've done a good chunk, I would challenge yourself to like just reviewing, right? So every question you see, you should be able to like know the path within 5 minutes. Yeah, right. And you just know when you know when you can solve the question, right? And stuff that you're kind of hesitant, spend a little bit more time and just put deadline on them, right? So let's just say you struggle a little bit, say, hey, in 3 days later I'm going to revisit this. So you have like a little Notion board, a Trello board of all the questions you've done. And since you're good, did a good job, just focus on your weaknesses. The question you're like, uh, sure, you may be good at everything, but there's one part where I'm just a little tad slower. So you just sharpen your knives, make sure you're just doing it. I used to do like 3 questions a day, and I test myself on everything for the past week on a Sunday. So I put all 3 days, 6 days, so 18 questions. I put it all on one page and just recode everything, right? And I did on a weekly basis. And yeah, just do that. And you're a super expert, then every question you look at, try to do very new questions or ask Claude or ChatGPT to be like, hey, I did all this, I want more better questions to really challenge myself, right? You don't want to, you know, Hello, do you hear me? Oh, uh, say you transfer.
Analog Ibex: Hello, can you hear me?
Stealthy Elephant: Yes, hello? Oh, yeah, sounds good, sounds good. Yes, I think what I was saying is just, you know, have that structure of just doing all those questions. Yeah, you should be good. And then I'm assuming— how are you on the system design portion?
Analog Ibex: Um, yeah, I mean, uh, I've done a couple— I've done a lot of rounds like maybe last year, 2 years ago, but like yeah, I haven't practiced in a while, so I'm probably rusty.
Stealthy Elephant: Yeah, okay, sounds good. And I would say the last few I would give you is to really put you in the senior engineer level. Yeah. It's just like those little things, right? Like just being proactive, figuring out like having a format. You run the test cases, you solve it, here are the edge cases, boom, you solve it. Hey, here's the time and space complexity. And then you would just, you know, any like bug issues where you talk through it, I think that would really push you to the next level. As a mid-level, I think you should be good. I think senior year, you are getting there, so just be more stern. Don't say anything like that would hurt you in the interviews, and you should be good.
Analog Ibex: Sounds good, yeah, well, thank you so much. This is definitely super helpful, so thank you, and I really enjoyed the questions, yeah.
Stealthy Elephant: Pretty good, no, thank you, thank you. Yeah, I made the second one myself.
Analog Ibex: Yeah, yeah, that's cool. I mean, it's good 'cause like it pushes me to like actually dissect the patterns instead of like, oh, like this was like given out to me like on a silver platter, so it's good.
Stealthy Elephant: Yeah, yeah, you never know, like they can give you curveballs. I always suggest everyone to just assume you have the worst interviewer out there, right? Yeah, like maybe you can't understand them, maybe like you just, you have to roll with the punches, right? At the end of the day, like it's what they think of you, right? And you just try to optimize every possibility for you to not fail. Yeah, makes sense. All right, best of luck in your interviews. I think you got this. Keep me updated. I'll always share my contact, so feel free to update me or if you have any other questions.
Analog Ibex: Awesome. Yeah, thank you so much. Alright, thank you. Have a good day. Alright, bye-bye. Bye.

We know exactly what to do and say to get the company, title, and salary you want.

Interview prep and job hunting are chaos and pain. We can help. Really.