Interview with a FAANG engineer.
We helped write the sequel to "Cracking the Coding Interview". Read 9 chapters for free
Longest Consecutive Sequence & Cliff Tree Stability
Watch someone solve the the problem: longest consecutive sequence 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.
Interview Summary
Problem type
The Problem: Longest Consecutive Sequence
Interview question
Given an unsorted array of integers, return the length of the longest consecutive element sequence (e.g., 1, 2, 3, 4). The elements do not need to appear in order within the array - they simply need to exist. The optimal solution requires O(n) time, pushing beyond the intuitive sort-based O(n log n) approach by leveraging a hash set to identify sequence start points and expand outward.
Interview Feedback
Feedback about Intergalactic Thunderstorm (the interviewee)
Advance this person to the next round?
No
How were their technical skills?
3/4
How was their problem solving ability?
3/4
What about their communication ability?
3/4
## Areas of Strength - Strong ability to handle complex, multi-part questions without getting intimidated - Good at clarifying the problem before diving in — asked the right questions to understand direction - Communicated well throughout — able to talk through the problem line by line - Showed awareness of efficient data structures — was moving in the right direction with hash sets and hash maps - Noticeably stronger on the second question — shows the ability to ramp up mid-interview --- ## Room for Improvement - Got bogged down on the first question — made assumptions instead of asking clarifying questions upfront, particularly around duplicates - If a question is unclear, keep asking until it fully makes sense — diving in without understanding the problem will hurt more than the time spent clarifying - For a senior role, always lead with the most efficient solution rather than defaulting to brute force — before writing anything, ask yourself if there is a more optimal approach available. Only walk through brute force if it is a necessary stepping stone to get to the efficient solution - Problem decomposition needs work — break the question into smaller pieces before jumping to code. A consecutive sequence has a start and an end — working backwards from that insight leads naturally to the right data structure - Do not overcomplicate the data structure choice early on — in most cases a set or hash map is the right starting point before reaching for graphs or more complex structures - Do not run the code until you are 95% confident it will work — at the senior level the expectation is that you trace through the solution line by line mentally before executing. Running it to see what happens signals a lack of confidence and interviewers do take note of it --- ## Things to Do Differently in the Next Interview - Always ask clarifying questions upfront — especially about edge cases like duplicates - If you do not understand the question, keep asking until you do. It is completely acceptable and expected - Before diving into code, check in with the interviewer — say something like "I think I am ready to go, am I heading in the right direction?" Read the room and adjust based on their tone and body language - If you feel the interviewer nudging you in a direction, follow it. You can even ask directly — "It seems like I may not be going the right way, should I rethink this?" Most interviewers will guide you - Treat it as a collaborative technical conversation, not a one-way test - Always ask yourself before coding — what is the most efficient solution here, and what is the right data structure to use - Be clock aware — in the first 20 minutes, push to finish the problem as fast as possible while keeping correctness and efficiency in mind. Having that time awareness in the back of your head will help with pacing across the full interview --- ## Open Notes One month of prep is a solid start. The main recommendation going forward is a structured daily practice routine: - Do three to four LeetCode questions per day from NeetCode 75 or NeetCode 150, focusing on the problem types you are weakest in - Spend no more than five to eight minutes attempting a question before looking at the solution if stuck — the goal is pattern recognition, not grinding through every problem cold - Come back to any unsolved question three days later and attempt it again - At the end of every week, redo all the questions from that week — if you did three questions a day for six days, that is 18 questions to review on Sunday - For a senior role, system design is also on the table — do one system design question per day alongside two to three LeetCode questions - Do not get burnt out. Consistency over intensity. The instincts are there. The gap right now is execution speed, confidence in the solution before running it, and leading with optimal approaches from the start. That closes with deliberate practice.
Feedback about Stealthy Elephant (the interviewer)
Would you want to work with this person?
Yes
How excited would you be to work with them?
3/4
How good were the questions?
3/4
How helpful was your interviewer in guiding you to the solution(s)?
3/4
Interview Transcript
Intergalactic Thunderstorm: Hey!
Stealthy Elephant: Hey, nice to meet you. Yes, so the way I usually do this interview is the first 3 minutes would just be a brief introduction of each other. Next, okay, 45 to 50 minutes will be 2 technical questions, and the last 5, 10 5 minutes would be a debrief and feedback session. Other than that, do you have any other questions before I move forward?
Intergalactic Thunderstorm: Uh, no, go ahead. I think your mic's a little muffled. Muffled? Okay, yeah, give me one second. Let me see if I can—
Stealthy Elephant: how about now? Am I still muffled?
Intergalactic Thunderstorm: I think it's still a little bit. It's not very clear.
Stealthy Elephant: No, it's very— okay, let me just Hello, do you hear me?
Intergalactic Thunderstorm: Uh, yeah, I can hear you.
Stealthy Elephant: Is this better now?
Intergalactic Thunderstorm: Uh, I think this is better, yeah.
Stealthy Elephant: Okay, perfect. All right, so yes, so my name is Selfie Elephant. I've been working as a data engineer at [REDACTED] the past 6 years. I've been doing a multitude of, you know, interviews from mock, like data structures, systems design, behavior, you name it. I'm working with them for a while, but yeah, I'm here to help you out and see how I can help you in your interview journey. Can you tell me a little bit more about yourself?
Intergalactic Thunderstorm: Sure, yeah, my name is [REDACTED]. I'm a CS grad from the University of Waterloo. I've got like, I guess about 6 years of experience now. Spent the first 2 years at [REDACTED] hedge fund in New York. Working on high-frequency trading stuff.
Stealthy Elephant: Nice.
Intergalactic Thunderstorm: And then spent 3 years working at a crypto startup.
Stealthy Elephant: Nice.
Intergalactic Thunderstorm: Like a 5-person crypto startup where I did all the smart contracts on a couple blockchains called Solana and Sui. Did that for 3 years, was pretty fun, but I think now I'm looking for something else. So just trying to see what's out there. Okay, perfect, perfect.
Stealthy Elephant: And you were going for a senior engineer Senior engineer level role, correct?
Intergalactic Thunderstorm: Yeah, I think with 6 years senior sounds right.
Stealthy Elephant: Perfect. Sounds good, sounds good. All right, let's do it. And are you in any type of final round interview right now?
Intergalactic Thunderstorm: Uh, no.
Stealthy Elephant: Got it, got it. All right, perfect. Let's get started. Okay, what will be your coding language of choice today?
Intergalactic Thunderstorm: Uh, Python. Yeah. Okay. Okay, all right, I'm gonna copy and paste the question right here. Yeah, feel free to go ahead. Okay, given an unsorted array of integer nums, return the length of the longest consecutive element sequence. Nums is this, uh, Okay, I actually don't even think I understand the first example. What is this longest consecutive sequence in example 1?
Stealthy Elephant: Sorry, say it again.
Intergalactic Thunderstorm: Uh, it says return the length of the longest consecutive element sequence, right?
Stealthy Elephant: Yes, correct.
Intergalactic Thunderstorm: Um, in example 1, uh, why is it 4? Like, what is the sequence?
Stealthy Elephant: Yes, so in here, what do you think, based on the 4, right, what do you think the consecutive element sequence is?
Intergalactic Thunderstorm: Uh, I am not sure, because I mean consecutive means like, like 4 and 3 are consecutive.
Stealthy Elephant: Mm-hmm. So when you say, yeah, so for this one, when you say consecutive, it's just You know, it's either in increasing or decreasing values of 1, right? So for this case, it doesn't mean it has to be like a subarray of longest consecutive element sequence, as long as there's a consecutive element sequence within this array, right? So for this one, it'll be 1, 2, 3, 4.
Intergalactic Thunderstorm: Uh, but they're not in Order.
Stealthy Elephant: Yeah, so it's more so it exists in the array. It doesn't have to be like a consecutive subarray that you see in line 5.
Intergalactic Thunderstorm: Uh, yeah, but like, um, for example, in the array, right, nums, like the order is 4, 1, 3, 2. So how exactly is that Consecutive?
Stealthy Elephant: Yes, correct. So it doesn't— it doesn't— when you say— when you see it like that, you're assuming that it's a subarray that has consecutive element sequence, right? We're saying in terms of the longest element sequence that exists in this array. So it doesn't have to be, you know, actually sorted as of now, as long as those numbers exist. So I can have maybe a 5 at the very front, a 6 at the very front, right? As long as those numbers can be kind of taken out And be provided in that sequence. It counts.
Intergalactic Thunderstorm: I see. I see. Okay. Okay. Um, I see. Okay. So, and then example 2, I guess it says 9. I guess you can make 0, 1, 2, 3, 4, 5, 6, 7, 8. And then, yeah, okay, so that's just length 9. Okay, I see. Okay, I think I understand the question now.
Stealthy Elephant: Yeah.
Intergalactic Thunderstorm: Um, okay, um, I guess just throwing some thoughts out there. I think if you sorted this array, um, and you just walked through it, uh, one by one, uh, you— it would be pretty clear to see what the longest subarrays are. Because, for example, sorting example 1 would give you 1, 2, 3, 4, then 100, 200. And it's like a pretty natural way to check if— check what the longest consecutive element sequence is.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: If the current element is 1 bigger than the previous, then we can increment our counter. If not, we reset and continue.
Stealthy Elephant: Okay, yep.
Intergalactic Thunderstorm: Um, does that make sense? And like, uh, should I just go ahead and try and code that up?
Stealthy Elephant: Yeah, that makes sense.
Intergalactic Thunderstorm: Yes. Cool. Okay. Longest, and I guess also nums length can be zero. I'm just gonna handle that case here. If not r, return zero. The longest. Well, actually, maybe I don't need to. Let's see. For v in R, v in R. Okay, so I'm just going to sketch out the solution, and then I think there'll be some mistakes, and I'll try and just fix them.
Stealthy Elephant: Okay, great.
Intergalactic Thunderstorm: One more thing is if v is greater— is okay, v equals r plus 1, then longest plus equals 1, right?
Stealthy Elephant: Yes.
Intergalactic Thunderstorm: Else longest just equals 1. Which is v. And then if i equals 0, long if equals 1. Continue. Okay, so if— I'm just going to run this on— I'm just gonna trace it through here, or I guess, do you care if it like works correctly on the first try versus just me testing it out and seeing what happens?
Stealthy Elephant: Uh, no, I don't, I don't really, uh, I would say I would advise you to get the solution correct first, or maybe at least algorithmically, and if you feel confident that it'll run, then by all means, you can run it.
Intergalactic Thunderstorm: Got it, got it. Okay, then I'll just trace it through for now.
Stealthy Elephant: Okay, sure.
Intergalactic Thunderstorm: Um, okay, so when we are stepping through this i, um, okay, so i is initially here. So when i equals 0, longest equals 1. I guess I definitely don't need this. Um, longest equals 1, and then we can continue. Uh, and then— oh wait, sorry, let me— this is— this actually gets sorted. So because 1, 1— oh, sorry, I forgot what the array looked like. So it looks like 1, 2, 3, 4, 100, 200. Okay. So longest equals 1, continue to 2. So now if v equals arr , which is 1 plus 1, which equals 2. Then we increment longest, which is correct, and then we continue. Um, let me do the same thing here, and then we do the same thing— oh, sorry, we do the same thing here, and then the same thing here. Uh, and then when we get to 100, 100 does not equal 4 plus 1. So— oh, whoops. Um, okay, I know where I made the mistake.
Stealthy Elephant: Curl in.
Intergalactic Thunderstorm: And then longest equals max curl in longest.
Stealthy Elephant: Cool.
Intergalactic Thunderstorm: Okay, so, and then when we get to 100, um, we know that this if condition is not satisfied, so we max longest with its current length, which is 4 and 0. Uh, And then we continue. I guess we can do this every time, which I think saves a step.
Stealthy Elephant: Okay.
Intergalactic Thunderstorm: Uh, so now when we're at longest equals— we're back at, uh, sorry, current length equals 1. Um, and then you go here, uh, current length equals 1 again. And then we end up returning longest.
Stealthy Elephant: Cool.
Intergalactic Thunderstorm: So, I think this works. Um, I do want to try running it if that's okay with you.
Stealthy Elephant: Sure.
Intergalactic Thunderstorm: Okay. So, if you do print. Oh, it ran up there. Okay.
Stealthy Elephant: Mm-hmm. Cool.
Intergalactic Thunderstorm: Oh, 2 is not correct. Why did it think—
Stealthy Elephant: oh.
Intergalactic Thunderstorm: Oh, I think I misunderstood the question. Um, or I guess I forgot to consider duplicates. So, um, when you sort them, you end up with duplicates that can affect your answer.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: Um, which is a little unfortunate. Um, I guess the easy fix is to just skip over duplicates.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: And that actually, I think, just works. I don't think that's missing anything.
Stealthy Elephant: Yeah.
Intergalactic Thunderstorm: Yeah, this is a little smelly. Do nothing. So curl— I mean, curl_end just equals curl_end. But I don't know. This looks kind of ugly. I think I can just write pass. Yeah. OK. I don't like this. I think rearranging this would make more sense.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: Okay, and then let's just see some other examples. So, like 0, this should just return— oh, this should return 1, actually. Why does this not return 1? Oh, oh, oops. Cool. So this returns 1.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: And then— cool.
Stealthy Elephant: Yeah, so what would be the space and time complexity for this?
Intergalactic Thunderstorm: So, time complexity, we're just iterating through the array once, so it's just O. Um, and then space complexity— uh, oh, sorry, wait, no, it's not O. I actually sort at the beginning, so it's, uh, n log n. Um, missed that line. Uh, and then, uh, space complexity, the array is sorted in place, um, so the only additional space we have are the 2 variables, longest and curl end. So the space complexity is O. Got it.
Stealthy Elephant: Yeah. So is there any way— so that's correct. Is there any way we can make this a more efficient solution?
Intergalactic Thunderstorm: Um, like in terms of time complexity?
Stealthy Elephant: Time complexity, correct.
Intergalactic Thunderstorm: So I think if you iterated through the array, um, so I guess you It's to make it more efficient, you can't sort. Um, so one idea I was thinking of, but well, nums has a really big range, which is, um, which probably won't make this work. But, uh, if you kept track, like say you put all the values into a set or something, or like, um, like a dictionary, then maybe— I was thinking maybe there's some way to iterate through the keys.
Stealthy Elephant: Yeah.
Intergalactic Thunderstorm: In a faster way, but I don't— I don't really see it because you still need a way to start from like the max key or like the minimum. value key and then jump to the next minimum.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: Um, I guess you could— oh no, that wouldn't work either. I was thinking maybe you could heapify, which is linear, and then pop elements, but that's not— uh, when you pop everything, that also ends up being, uh, n log n, I think.
Stealthy Elephant: I think, hmm, maybe think about— so you are correct that, of course, to make this more efficient, you cannot use the quicksort or the sort you have on line 22.
Intergalactic Thunderstorm: Yeah.
Stealthy Elephant: You would have to do like, you know, a couple passes, but you can't do, you know, like n squared pass or anything. I would advise you to think, what is The meaning of a sequence, right? What is exactly a sequence?
Intergalactic Thunderstorm: Oh, I guess When we pass an element, we know what its previous element and next element should be.
Stealthy Elephant: How do you know the previous element or next element? Are you using like a certain data structure for this?
Intergalactic Thunderstorm: So, well, sorry, I'm thinking of it more like, say these elements are now nodes in a graph.
Stealthy Elephant: Okay.
Intergalactic Thunderstorm: And now, like, say our element that we're currently iterating over is 4.
Stealthy Elephant: Sure.
Intergalactic Thunderstorm: Then we know that, uh, 4, like, 4 is between 3 and 5. So if we could somehow put an edge into, like, if we know that 3 exists and then put an edge from 4 to 3, uh, and then if we know 5 exists and put an edge from 4 to 5, uh, then we could iterate over this graph in like a DFS or just some other kind of traversal.
Stealthy Elephant: Yes, you are in somewhat in the right direction. I wouldn't say we need to the extent of graphs and edges and vertices. I would say there's even a more simpler data structure we can use. Right, because I know you're saying we— you are in the right— you're saying that, hey, if I'm looking at 4, we know that, hey, there's a 4 that exists or there's a 5 that exists, right? How would you—
Intergalactic Thunderstorm: Correct.
Stealthy Elephant: So when I ask you what is a sequence, what is a sequence to you, right? What is your definition of a sequence?
Intergalactic Thunderstorm: Um, there's like a previous element and a next element, I guess.
Stealthy Elephant: Yeah, so there's usually a start of a sequence and there's an ending of the sequence. How do you know that whatever current value we're looking at is the start of the sequence?
Intergalactic Thunderstorm: Um, well, uh, I guess it feels a little ambiguous. Like, one is just like the very first element in the array, the second is like the minimum element, or it has no Yeah, it's just the minimum element, slash it has no previous element.
Stealthy Elephant: Got it, yeah, so let's just say we have some type of data structure to store all the values for array.
Intergalactic Thunderstorm: Yeah.
Stealthy Elephant: Right, so if I'm looking at a 4, we know that this is not the beginning of a sequence because the number before, like minus 1 of 4, which is 3, exists in this array some way, somehow. We're allocating some type of memory, you know, this current number minus 1, which is 3, exists in this data structure, that means that, okay, this— we are in the middle of the sequence. But let's just say we are currently at 3 and say— or sorry, let's just say, for example, 1. We are currently at 1 and we say, does the number 1 minus 1, which is 0, equal in this array? If not, that means that we are at the very start of the sequence.
Intergalactic Thunderstorm: Got it. Yeah, I think I see what you mean. Like, if we— well, I guess I'm debating between using a set and a dictionary. But say we had a dictionary of all the elements that are in the array.
Stealthy Elephant: Yeah.
Intergalactic Thunderstorm: And then say we're at element 4.
Stealthy Elephant: Okay. Right? Yeah.
Intergalactic Thunderstorm: And then we check if element 3 exists in this dictionary.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: Um, then I guess the reason why I want to use a dictionary is because I wanted to store like, uh, like some kind of computation for the, for the value of 3.
Stealthy Elephant: Mm.
Intergalactic Thunderstorm: Um, because if we have 1, 2, and 3, then I want to store like the— I guess the longest consecutive sequence that ends at 3 in the dictionary, which would be 3. Oh, so then we get to—
Stealthy Elephant: yeah, so why do you want to, uh, store the computation? So you just want to store the computation for each number, is that correct?
Intergalactic Thunderstorm: Uh, that was my current idea, yeah.
Stealthy Elephant: Got it.
Intergalactic Thunderstorm: Or you could just like recurse down, see where it ends, and then, uh, keep track of the number there somehow.
Stealthy Elephant: Got it. So let's just say when we're— if we're going through this array and we're checking, hey, yeah, I know you said you're either using between a hash map or a hash set, right? So let's just say you go through one. Let's just say example 1: 100, 4, 200, 1, 3, 2. It seems like once we're in the middle of a sequence, do we really If there's— if we always know for sure there's a start of a sequence in this array and there's a middle of a sequence, I feel that we only need to focus on the start of sequences, right? Because if we are at the start of sequences and we know that it's always consecutive, right, it's always plus 1 of something.
Intergalactic Thunderstorm: Yeah, okay, so I guess if we knew the start, if we knew all the starts in the sequence, Yep. We can iterate through until the end of the sequence, and then we would have the value of the longest sequence.
Stealthy Elephant: Yes, correct.
Intergalactic Thunderstorm: Cool. Okay, I think that makes sense.
Stealthy Elephant: And how would you get that longest sequence, right? Let's just say we're at the, you know, we're at this current value. How would we get the longest sequence?
Intergalactic Thunderstorm: So, if you have— if you know where to start, let's say we find an element where there, like, a previous value does not exist in the array, then we know where to start. And then we just keep traversing through this dictionary to find the next value from the start until the next value no longer exists.
Stealthy Elephant: Okay, yeah.
Intergalactic Thunderstorm: And once you know— and while we're doing that, we're incrementing our counter by 1.
Stealthy Elephant: Mm, okay, got it. Yeah, if I can advise you, instead of maybe going to the dictionary, we can also just do, you know, just do like a plus 1 while loop, because then we always know that it's always consecutive. But I think either way would work for you.
Intergalactic Thunderstorm: Oh, got it, got it. Okay, I see, I see. I guess you don't even need to do the plus 1 because you can just difference the, the elements.
Stealthy Elephant: I see.
Intergalactic Thunderstorm: Okay.
Stealthy Elephant: By all means, so I think that's the right direction, so feel free to, uh, code out or implement it.
Intergalactic Thunderstorm: Okay, um, I'm just gonna save these. Okay, so we'll set How do I find starts equals v for v in values if v minus 1 not in values? Cool. So I'm just gonna actually— I'm just gonna work through this incrementally. So I'm just gonna print starts. And I'm just gonna delete this for now, I guess, since that's private solution.
Stealthy Elephant: Okay.
Intergalactic Thunderstorm: Okay, so let's just print this out. Unhashable type list. Oh, oops. Um, 1, 100, 200. Cool. Yeah, so these are reasonable starts, or I mean, these are all the starts. Um, For start in starts, while— Curve plus 1. Curve plus 1 in values. Curve less equals 1. So this iterates until, uh, until there's no next element. Um, and then let's just say longest 0. So, when we end, curr plus 1 is not in values, but curr is in values. Uh, so longest equals max longest, curr minus start plus 1. Let me just print this out. For— cool. Yeah, I think that actually does work. Cool. Yeah, so this seems to work. And then the time complexity. Yeah, I do a couple iterations through the array, but like I guess my claim is like the total number of iterations here is just still O.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: Because this while loop only ever increments if the value exists in the array, and then we're not going to go over the same element twice. Okay, perfect. Yeah.
Stealthy Elephant: Looks good.
Intergalactic Thunderstorm: Okay, perfect. Let's—
Stealthy Elephant: are you ready to move on to the next question?
Intergalactic Thunderstorm: Uh, yep. Perfect.
Stealthy Elephant: All right, let me just do this.
Intergalactic Thunderstorm: Okay, here we go. Okay, you are a landscape designer working on a vertical cliff covered with trees. Cliff's model is a 2D grid. 1 is a tree, 0 is a rock. The bottom row is solid ground. 2 trees are connected if they are adjacent up, down, left, or right. Trees can be stable if connected to other trees to at least one tree in the bottom row. The tree is not connected to any other tree— to any tree in the bottom row It'll fall off the cliff and disappear. You are given grid plus coordinate representing the tree you cut down. Uh, cutting the tree means— After that, any trees that are no longer stable will also fall and become 0. Okay, so ignoring the cut thing for a second, I guess.
Stealthy Elephant: Okay.
Intergalactic Thunderstorm: To find trees that are stable, That just means like a tree is stable if it— if there's some path to the ground. So to find all stable trees, you can just like DFS from the ground to see which trees are connected to it. So then we can get this like mapping of which trees are stable and which ones are not. And then I don't really know what the significance of the cut is. Like, it just seems like all the unstable trees are going to fall no matter what. Unless I'm misunderstanding something.
Stealthy Elephant: Oh yes, you do.
Intergalactic Thunderstorm: Okay, okay, so, so cutting the tree— so I got to cut the tree and then find the ones that are stable. I can find the ones that are stable and then I cut the tree, then some answers could be wrong.
Stealthy Elephant: Correct, correct. All right, so for example, I gave you line 26 and 29. This is one example. So if we cut 1, 3, what Part of the tree still remains stable.
Intergalactic Thunderstorm: Okay, so row 1, column 3. So if we cut this, yeah, then this, this tree is stable. So I guess this entire row column is still stable. Okay, yeah, column 2. And then the tree on the left and the right are also stable. And then I guess everything else dies. So like that, uh, like this, this dies.
Stealthy Elephant: Can you make it to zoom?
Intergalactic Thunderstorm: Oh, oh, sure. So I can—
Stealthy Elephant: yeah, perfect. Sounds good. Yep, yeah, exactly. And then let me give you another example.
Intergalactic Thunderstorm: Uh, okay, okay, so let's just say you do this. This.
Stealthy Elephant: Okay, and then it'll be the same cut, so what will be the output?
Intergalactic Thunderstorm: Same cut. Okay, so 1, row 1, column 3. So if I cut this, these all survive, correct? Perfect, right? Yeah. Yeah. All right, sounds good.
Stealthy Elephant: So it seems like you got the, the logic of the question. How would you approach this algorithmically?
Intergalactic Thunderstorm: So I guess I'm given the grid. So initially I would cut the tree, so it turned that cell into 0. And then I would iterate through all the ground cells and kick off a DFS, more or less. And I'm just like, DFSing through all the 1s. And the goal is when I'm DFSing through all the 1s in this grid, I will get all the stable trees. And then from that, I can find the unstable trees pretty easily.
Stealthy Elephant: Mm-hm.
Intergalactic Thunderstorm: By iter— well, I guess I can iterate through the grid again, and then if a tree is not stable, I just turn it to 0, and then I return the grid.
Stealthy Elephant: Yeah, I think this is in the right direction.
Intergalactic Thunderstorm: Cool. Okay, so I'm gonna try and implement this find cut— let's just say cut unstable trees, and I'm given a grid. Right, grid and then cut c. Grid cut r cut c equals 0. And then stable trees equals find stable trees, right? Grid— oops. And then for row in grid, for— For row in enumerate grid, for c now in enumerate row. If rc not in stable trees, grid rc equals 0, return grid. This is the high-level solution. I'm just going to delete all of this. No, it's just complaining. Uh-oh, cut r. Find stable trees grid. Okay, just say return. Okay, I guess I don't know what I'm doing here yet, but All right, so how many— what is the bound for this? Range when grid 0. If grid Grid minus 1. j equals 1. So at the bottom cells here, is it 1? Is it— Okay, so I need to test this.
Stealthy Elephant: I gave you an example, right? You can copy and paste line 25 to 30.
Intergalactic Thunderstorm: Line 20— oh, perfect. Thank you. Okay. Okay, so— oh, right, you said this grid. Okay, so then I just want to run find_stable_trees first because that's like the meat of the function. Um, and we'll see what happens. Oh, I guess it gets printed.
Stealthy Elephant: Twice.
Intergalactic Thunderstorm: Okay, so 1, 2, 1, 5, 1, 1, 0, 3, 1, 4, 0, 2, 0, 5, 2, 2, 3, 2, And then 1, 3, and then does it have 0, 1, 2, 3, 3, 2? Yeah, okay, it does. I mean, this seems like it works. Um, those are all the stable trees. Uh, Let me just run this real quickly. Yeah, it seems fine. And then we're going to cut 1, 3. Okay, so if I do find What is it called? Oh, right. Cut unstable— nope. Cut unstable trees grid. And then we're cutting 1, 3. And let's just see what happens if I run this. Okay, it'd be nicer to print this out in a slightly better way. For row in grid, grid row. Okay, so then if we run this— Nice, nice, cool. Uh, well, I've Was this the one where just the— oh, okay. Yeah, this looks right. Yes, correct.
Stealthy Elephant: Yep, that is correct. And then can you run that second test case?
Intergalactic Thunderstorm: Yeah, uh, sorry, where's the second one?
Stealthy Elephant: Second one is— you had it here.
Intergalactic Thunderstorm: Oh, okay.
Stealthy Elephant: So, like this, uh, let me copy and paste the same one you had before. Fill in the ones. So copy and paste line 25 to 30, and then here, I'll do this.
Intergalactic Thunderstorm: One second.
Stealthy Elephant: All right.
Intergalactic Thunderstorm: Oh, okay.
Stealthy Elephant: Now copy and paste.
Intergalactic Thunderstorm: Cool. Yeah, this seems to work because everything remains except the thing we cut, right?
Stealthy Elephant: Yes.
Intergalactic Thunderstorm: Perfect.
Stealthy Elephant: All right. Yeah, looks good. What is the time and space complexity for this?
Intergalactic Thunderstorm: So, um, the space complexity depends on— well, I guess the stable trees can be O. Because, you know, like, in the worst case, every single cell has a tree and it's all stable.
Stealthy Elephant: Mm-hmm.
Intergalactic Thunderstorm: And then the time complexity of the actual function is just O, because we're— and at the worst case, we're going to iterate through every single element in the grid. But never— like, we're not going to duplicate elements in the grid because of the visited set check. Um, I think there is a way to improve the space complexity. Um, well, because I think of instead of, um, returning stable trees as a new array, you can like modify the existing grid with some special values. Um, So if I had to lean towards optimizing, I think that's the direction I would go.
Stealthy Elephant: Okay. I, I think your time-space is fine. I think everything is good. Uh, so if you can just write down what's your time-space. You said O, assuming that the grid is exactly n by n, correct?
Intergalactic Thunderstorm: Correct, yeah. Um, or m by n if the grid is rectangular. All right, no, sounds great.
Stealthy Elephant: Yeah, okay, all right, this sums up and you are done with both questions. Are you ready to go to the feedback section?
Intergalactic Thunderstorm: Uh, yeah, for sure. All right, perfect. Let me just put my notes out. Okay, okay.
Stealthy Elephant: So the way I usually structure this feedback are in 4 sections. So there are 1, areas of strength, number 2, room for improvement, number 3, what you should do definitely in the next interview, and number 4 is open notes, right? So just before I go in, how long have you been prepping for these type of interviews?
Intergalactic Thunderstorm: Um, I would say like roughly a month. Like I've worked through, uh, the Cracking the Coding Interview book. Yeah, and then some [REDACTED].
Stealthy Elephant: Okay, nice. So for your areas of strength, I think you, you're able to— for at least for the second question, you're able to understand, like, for a bigger complex question, like maybe sometimes people might think it's daunting, you're able to kind of just clarify what you need to do, which direction you have to go in, and you're clarifying questions. So I felt like you're able to communicate through that and go line by line. That's one. In terms of room for improvement, the first question is maybe where you got boggled up on. There are some— there were some assumptions made, I felt like, maybe about the duplicates, right?
Intergalactic Thunderstorm: Mm-hmm.
Stealthy Elephant: Ask about that next time. And sometimes I know maybe the question may not be straightforward, right? So that can happen anywhere. So in any kinds of questions, feel free to just keep asking questions like, hey, I don't understand what this happening? Why is this the answer? Can you walk me through an example, right? Of course, by all means, just keep asking until you understand, because if you don't understand the question and you dive into it, it's not going to help you at the end of the day.
Intergalactic Thunderstorm: Yeah.
Stealthy Elephant: In terms of other improvement is like the problem solving, right? So I know you went to the brute force solution. I would advise for as a senior role, you always try to get the most efficient solution at the very beginning just to help out with the pacing. Right. So when you do like a brute force, always try to ask yourself, hey, is there— before I dive into this, is there any way I can do a more efficient solution? I would only advise you to do it, the brute force, if there's, you know, you have to get through this specific method, therefore you can get to the second one. So try to think about that before you dive into brute force. In terms of problem solving, just try to actually— try to ask yourself more questions in terms of what the question is asking. asking, right? In terms of, hey, it's a consecutive sequence of numbers, right? So I think I was trying to ask you, hey, what is a sequence to you, right? So I hope you say, hey, a sequence has a start and end, right? You're trying to figure out, you know, you just try to break down into little pieces. And from, you know, insinuating that there is a start, you got to figure out, okay, maybe I need to use some type of data structure, right? You have to leverage some type of data structure so you don't have to do like an n squared pass. You can, you can do multiple passes throughout, right? As long as you either store the data somewhere, so you have to leverage the data. And you were in the right direction of like the HashSet and HashMap. Try maybe not to overcomplicate at first, right? I know you were going to the graphs of sets and vertices, right? Usually in these type of questions, you go with Set or HashMap, and—
Intergalactic Thunderstorm: Mm-hmm.
Stealthy Elephant: That would be your best bet, right? So I think you're able to kind of get through that. In terms of, you know, just getting the most efficient solution. And I think it took a little bit to get there. I would say just to slow down a little bit, see what data— what specific data structure you use to leverage, which was the hash or hash map. And then 2, just ask yourself inner questions of, hey, how can I— like, what is the sequence? What is this? And then just work backwards from there. I think that would definitely help in terms of the room for improvement, right? And just ask clarifying questions, right? the duplicacy. Even if you do, let's just say hypothetically between you and I, if you miss that, say, oh yeah, also I recall I have to handle duplicacy. You don't have to admit that, hey, I did not— I made this wrong assumption. Feel free, by all means, you don't have to mention it out loud. Just say, hey, also I just want to make sure I covered this duplicacy. And then just fix it, right? Just fix it and then some of the interviewers are like, oh, perfect, like this person fixed at the end, so it's totally fine. Don't admit fault. right away. Just go through it line by line. If you feel like you made a small mistake, try to cover yourself up, but if it's super obvious, by all means, don't dip it. Another rule for improvement is, yes, I would not advise you to run the code until you are 95% confident that it's going to run.
Intergalactic Thunderstorm: Got it.
Stealthy Elephant: A lot of— I think the bar for seniors is that you don't run the code and then backwards engineer why it's not working. You always, you know, analytically go through it. Hey, this is the best solution. I'm gonna run a specific test case line by line. Perfect. Based on what I've done, this should work. Oh, okay, it doesn't work. There might be some bugs. Let me fix it, right? Go, go from that mindset. Don't think of, hey, do you mind if I just run this stuff and see if it works? No, I feel like a lot of, at least from my experience, a lot of interviewers these days, it they do dock points off of it, right?
Intergalactic Thunderstorm: So I'm— Got it.
Stealthy Elephant: You ask me, hey, is it okay, right? So I would say technically no, I don't do it, but I know a lot of other interviewers, they do kind of— they don't dock it officially, they'll be like, okay, this person is not confident in the first ability, right? I would assume as a senior you have everything set. So I, I was— I would be— that would be the best advice I can give you in terms of open notes. Sorry, sorry, not openness, but things what you should do differently in the next interview. So ask more questions, right? Ask more questions. Always look out for the duplicates. Always make sure you understand the question. If you don't understand, just keep asking. By all means, it's okay. Number 2, always ask for clarifying details like, hey, I think I'm ready to go, or do you think I'm in the right direction? Like, by all means, you can do that. You can ask me that and I'll be like, oh yes, of course you are in, or maybe, eh, you can read the room. You can see how the interviewer's body language is, either through the video call or just through the tone of their voice. If you feel like they're kind of pushing you somewhere, right, go with that direction. Or you can even double down. You can even ask them like, hey, like, it seems like I'm not, I'm not too sure if I'm going the right direction, right? And then they'll be like, uh—
Intergalactic Thunderstorm: Got it.
Stealthy Elephant: Either they're gonna say, if they're, you know, if they're not the nicest interviewer, they'll be like, I can't answer that. But 95% of the time, they're like, oh yeah, I think you should look into this. So feel free to kind of treat it as a casual technical interview, right? You're kind of— you two are just kind of working together, right? And another thing I would do differently is ask yourself clarifying questions, make sure you're always doing the most efficient solution, right? So I think that would be your best bet. In terms of open notes, I know you've done like interview prep for a month, right? The most cliché thing is just doing practice, but I always offer like this specific mindset of— Hey, do 3 questions per day from NEET Code 75, NEET Code 150, whatever you think is best to get the overall understanding. Like, it seems like you did the second question you were stronger at, so I would advise you to, you know, do more of the ones that you are— may not be the best at. So do 3 to 4 questions a day depending on your work schedule. Don't get burnt out. Then you put a deadline on each question. Hey, I— if I don't do so well on the first attempt, I'm gonna— I'll solve it now, but I will come back to it 3 days later, right? And I would only advise you to spend 5 to 8 minutes max on the question, right? And like, you might be able to solve it by the 10th minute, by the 14th minute, but I want you to challenge yourself to think like pattern matching. I see this question, what do I do? Boom, boom, boom. Hey, if I don't understand within the first 5 minutes, it might take you a little longer time, right? Totally fine.
Intergalactic Thunderstorm: Gotcha.
Stealthy Elephant: Put the solution and just come back to it 3 days later. And at the Sunday of every week, I would just test myself on all the questions I've done, right? So maybe you've done 3 questions a day, 6 days a week. There's 18 questions you gotta redo by Sunday. And I would just keep iterating through that. And I know for a senior engineer, you do have to do system design. So of course, go through the system design interview questions and do the same type of format. It may take a little bit longer, so just do maybe 1 system design per day, maybe 2 to 3 [REDACTED] questions, and I think you have a solid schedule.
Intergalactic Thunderstorm: Got it. Um, okay, so I guess to summarize, I think in the first question, uh, I didn't do— I only worked through the first 2 examples, and if I worked through the third one, I would have noticed the duplicates thing. So I just overlooked, uh, that. So that's something good to know.
Stealthy Elephant: Uh-huh.
Intergalactic Thunderstorm: Um, regarding the efficient versus inefficient solution, um, are you saying if I asked you if Like with my first solution, if I said— if I asked you to— if it was okay, you would have said no? Or—
Stealthy Elephant: So as an interviewer, we always look for the interviewee themselves acknowledge that there might be a more efficient solution, right?
Intergalactic Thunderstorm: Got it.
Stealthy Elephant: Like, you know, because everyone's always attempt is always quick sort, sort it and run it through. Right? So I would— you can run it, right? But you should say, huh, is there a more efficient solution for it? Let me think a little bit, right? It's n log n, right? A lot of solutions these days is usually O or whatever, right? So I would advise you to just like think back. And then if you were asking, huh, this is the brute force solution, but I do have a feeling there might be a more efficient solution, right?
Intergalactic Thunderstorm: Yeah.
Stealthy Elephant: I mean, you can ask. I would say yes. Hey, is this like a more efficient solution? But I would have wanted you to just come to it yourself and see, huh, maybe like I can't really think of something, can I just do a brute force? I would say yes as well. Or you can say, um, let me take some time, let me think of a more efficient solution. And then if I don't say anything, or I'll let you do rock, I'll let you go through it, like you can take that hint. But most of the 95% of time, there's a more efficient solution of O. Unless it's—
Intergalactic Thunderstorm: unless the interviewer— Got it.
Stealthy Elephant: Gives you like a really complicated question the first round. Yes, the first question is always the easier one. And oh, sorry, second thing is work on your pacing, right? I know you did solve the second question very solid, right? So you had no issues. But I know sometimes like you spend a little bit longer on the first question and some people can't finish the second one. So just be careful with that. So when you do 2 questions, like You can ask the interviewer straight up, hey, how many questions are you asking me? They'll probably say 2, and you know, you can look at your clock, you can say, hey, first 20 minutes I'm trying to finish this as fast as possible. Of course, right, make sure it's efficient, but just have that in the back of your mind.
Intergalactic Thunderstorm: Okay, yeah, yeah, that makes sense to me.
Stealthy Elephant: Okay, yeah, do you have any questions about the feedback?
Intergalactic Thunderstorm: Uh, no, I think it makes sense. Uh, I guess in your opinion, like, do you, do you feel like you gave too many hints in the first question?
Stealthy Elephant: For me?
Intergalactic Thunderstorm: Or was this like a normal back and forth?
Stealthy Elephant: Yeah, yeah, so I did give a little bit too many hints, right, because you were, you were reaching that 30-minute mark, right? So I read you kind of— I was, it was, I wasn't giving you outright hints, I was giving you like just asking questions to push you into that because I can see you were getting stuck and you're going through some different rabbit holes. I feel like if I didn't give a little nudge, we might have spent a little longer. I'd rather you kind of struggle through it, I'll give you a hint, struggle through it, give you the hint, and then you figure it out. And so you can still have time to do the second question.
Intergalactic Thunderstorm: Got it. Okay, uh, yeah, uh, all this makes sense to me. It was good feedback, so thank you.
Stealthy Elephant: Appreciate it. But yeah, other than that, let me know if you have any other questions through email or anything, but I appreciate your time. Thank you.
Intergalactic Thunderstorm: Perfect, thank you.
Stealthy Elephant: Thank you.
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.