Python Interview with an Atlassian engineer.

Longest Consecutive Sequence & Tree Cutting Simulation

Watch someone solve the longest consecutive sequence & tree cutting simulation problem in an interview with an Atlassian engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.

Longest Consecutive Sequence & Tree Cutting Simulation: Python Interview with a FAANG Engineer - YouTube

Interview Summary

Problem type
Longest Consecutive Sequence & Tree Cutting Simulation

Interview question
Problem 1: Given an unsorted array of integers, find the length of the longest consecutive element sequence. The solution must handle duplicates and large input sizes, with the optimal approach achieving O(n) time using a HashSet to avoid redundant sequence traversals.
Problem 2: Given an m×n binary grid representing a forest, simulate cutting a tree at a given cell (r, c). The cut cell becomes 0, and any connected 1-cells that are no longer reachable from the ground row (bottom row) must also become 0. The challenge requires a DFS-based reachability check to determine which cells lose their connection to the root after the cut.

Interview Feedback

Feedback about The Mighty Pumpkin (the interviewee)

Advance this person to the next round? No

How were their technical skills? 3/4
How was their problem solving ability? 2/4
What about their communication ability? 3/4

Strengths

Room for Improvement

Do Differently in the Next Interview

Open Notes / Action Plan

Interview Transcript

The Mighty Pumpkin: Hello? Hello, do you hear me? Hello?
Stealthy Elephant: Oh no, I can't— hey, my puppy, I can't hear you as of now. Oh, there you go, I hear a little bit. Hello? Yeah, hello.
The Mighty Pumpkin: Okay, that's good. Can you hear me?
Stealthy Elephant: I hear you. Perfect, perfect. All right, sounds great. So my name is Stealthy Elephant. The way I usually do these interviews is the first 3 minutes will be a brief introduction of each other, and it would be just, you know, just going through where you're currently in the stage right now, and the next 45 minutes will be just 2 technical questions, I would say, and the last 5 minutes would be like a debriefing feedback. Do you have any questions about the structure?
The Mighty Pumpkin: No, I'm good. Sounds good.
Stealthy Elephant: Perfect. Yeah, my name is Stealthy Elephant. I've been working as a data engineer at Atlassian for the past 6 years, so I've been doing a multitude of experience interviews for data structure, system, behavioral, anything you name it. So I might— my goal is just to help you out with, you know, the weaknesses you may have or any kinks that you feel like you should sharpen, um, so that you can do better in the next interview. Hey, can you tell me a little bit more about yourself and where are you currently in the interview process?
The Mighty Pumpkin: Yeah, so I'm a senior software engineer, uh, working at [REDACTED], and right now I'm actively interviewing, um, on-site stages. Many places I'm failing in the phone screen or Um, for systems, I think the expectation is something different, which I'm not able to decode. Uh, these days there is just like one coding question and then one system design scenario is what I'm being asked in a few places, um, like [REDACTED] and, uh, [REDACTED]. And a few places I asked. So I don't know which round I'm failing, but it's about like, um, yeah, given a system scenario, can you please design, uh, something like a logging agent? And it's about— the prompt is about, let's just talk through it. But when I talk through it, I don't know, like I get a reject, so I don't know what I'm missing.
Stealthy Elephant: Yeah.
The Mighty Pumpkin: Um, and coding questions. So, okay, got it, got it, got it.
Stealthy Elephant: All right, okay. And do you have any interviews coming up? Final round?
The Mighty Pumpkin: Yeah, I have a few interviews like [REDACTED], [REDACTED] next week.
Stealthy Elephant: Okay, perfect. You are going for a senior engineer role or a staff level role?
The Mighty Pumpkin: Oh, senior.
Stealthy Elephant: Okay, perfect. All right, let's go ahead and get started.
The Mighty Pumpkin: Yeah.
Stealthy Elephant: Which language will you be coding in today?
The Mighty Pumpkin: Python. Sounds perfect. I'm gonna copy and paste the question. Okay, here you go. Here you go, start it. Given an unsorted array of integers, return the length of the longest consecutive element sequence. And it means like, or length, uh, the longest sequence of— okay, so like this is the sequence, so the order can be changed is what I meant to ask. Order is not, uh, constraints given and the checking is almost 100K point, uh, values can be anything. Okay. I guess like what I'm thinking here, and in this case when there are duplicates, only we only consider one element as a part of the sequence. I guess it's consecutive, but like this is not a valid sequence.
Stealthy Elephant: So then we're here, right? As you can see, the duplicates wouldn't be considered.
The Mighty Pumpkin: Sorry?
Stealthy Elephant: So duplicates would not be considered.
The Mighty Pumpkin: Oh, not considered. Okay, so just one. Okay, uh, I'm thinking then some sort of— if you could store the elements, either we sort and yeah, keep Start from 0, keep counting until the sequence breaks. So the next expected number should be 1 plus of the previous number, and if the sequence breaks, I record the total and use the maximum at the end. The complexity would be n log n to sort, and then plus O. And log n plus n. Uh, if we sort first and then loop once, keeping the count of sequence seen so far, or— But the space complexity would be constant, right? Uh, other way could be I store— so look through the elements, store them in the HashSet, and, um, Is that question or? So if I store them in the HashSet, in the first example it's like 100, then I'll store 4, and I can check if I have a 3 or a 2 in my HashSet. That would be a constant operation, and if it is, it It means there is some sort of a consecutive sequence. Uh, keep going. Um, 200, no. 1, it's not there. 3, it's not there. Or 3, when I hit 3, I will see 4. So the length would be 2. Then I see 2. Hmm, I guess I was thinking like whenever I hit a number, you keep checking for a sequence starting from that number in the— in loop. But that would be like, uh, O operation in worst case, because if Mm-hmm.
Stealthy Elephant: Yeah, yeah, I like that idea.
The Mighty Pumpkin: Sorry, you said what?
Stealthy Elephant: No, I like the idea.
The Mighty Pumpkin: Yeah, yeah. But, uh, I'm trying to think if there's a better way. And square, because I'm— in a way, if I see 4 and I've already seen a 3 and a 2, so I think the worst case for that scenario would be, um, 4, 3, 2, 1, 0. So I'll put 4 in my set, then see 3, and I— if I check for 4, I will find 4. So then I'll do 2 operations and my length would be 2. Then I hit 2. Um, I think I've seen this question before. Okay. Um, yeah, I guess we can do— oh, now I think I remember. Something is, uh, you only start checking if, if that's the smallest number in the sequence. Uh, But that won't help in this case because 1 is already there and we have not seen 2 at all. Okay. Okay, so to solve that, so the problem I was saying is maybe I should just do lookup in one direction And not in both directions. And that way I can just start from the smallest number I've seen so far and then start looking for a sequence. So I avoid duplicate work. Um, so for that I have to Um, I will just put the numbers in the set first and then again loop over the array. And if I don't have a previous, like a smaller number than the current array in the set, then I look— start looking for a consecutive sequence. So here it means we could have a sequence. Um, so let's have a variable which is 0, which will keep track of the next line, and then Um, if it is not there, then we have to check for, um, find length from this number in nums. So this will give you the sequence length starting from this particular number in the array, and then we just do So until it's present. Okay, just so I'll try with How do we run it? If I just hit run, does it work? Oh, it does.
Stealthy Elephant: Let's see.
The Mighty Pumpkin: 3, 9, 3, 9, 4, 3, 9, 4. Okay, yeah, so that's complexity would be O. Space is also Nice.
Stealthy Elephant: And what are some other edge cases that you, you want to handle?
The Mighty Pumpkin: Um, Oh, uh, one second. So then it's 0, but what if there is just one element? Then it will still work. Just checking the one element scenario. Okay, so one is also fine. Empty would also work because it should just say 0. Yeah, I think If we call duplicate, then also it will work because at least it will call once. Yeah, I mean, there could be some optimization we could do apart from edge case. Like, I think another bad case for this is something like this. Which we can prune if we— Yeah, if we record that we've already started a sequence from 1, then we don't have to keep like doing these calls again and again.
Stealthy Elephant: Mm-hmm.
The Mighty Pumpkin: Okay, so you have that.
Stealthy Elephant: And then can you also add maybe like— well, there's only—
The Mighty Pumpkin: okay, I see it.
Stealthy Elephant: Okay, sounds good. Time-space continuity. All right, let's move on to the next question.
The Mighty Pumpkin: Okay, perfect.
Stealthy Elephant: Is there a fire alarm in the background?
The Mighty Pumpkin: Yeah, no problem, take your time. Okay.
Stealthy Elephant: I'm gonna copy and paste the next question.
The Mighty Pumpkin: Okay, I'm gonna copy it. Give me one second. Right here. There you go.
Stealthy Elephant: Okay.
The Mighty Pumpkin: You are given an m cross n grid landscape, 0 and 1, according to cut. We present cut down. Cutting this tree means the cell RC becomes 0 first. After that, any tree that are no longer stable Oh, okay. So the tree, tree is not just a straight line, is that?
Stealthy Elephant: No, right now. Here you go.
The Mighty Pumpkin: Okay, yeah, bottom index. Okay, so from the tree can only start from row 3, right? I guess logically.
Stealthy Elephant: Say again, what's your question?
The Mighty Pumpkin: From row 3 is where the tree starts always.
Stealthy Elephant: Yeah.
The Mighty Pumpkin: Uh-huh.
Stealthy Elephant: So this is, this is not to confuse you, this is the column indices, right? So this, you will have this one, right?
The Mighty Pumpkin: Um, yeah, but in this case, like, all the highlighted ones is just one tree?
Stealthy Elephant: Uh, yes, anything that's one, one tree.
The Mighty Pumpkin: No, so Yeah, like here from row 3, this 1 starts, then this 1, and then all these 1s.
Stealthy Elephant: Yes.
The Mighty Pumpkin: Uh, this is just part of one tree. So if, if I cut this as per the question, it means this and all these 1s in row 0 and 1 and row 2 all become 0.
Stealthy Elephant: Yes, correct.
The Mighty Pumpkin: Interesting. But row 1— oh, sorry, row 3 remains 1. And if there is a 3 here, for example, these also remain 1, correct?
Stealthy Elephant: Yes.
The Mighty Pumpkin: OK. Cut 1, 3. 1, 3. Oh, in this case, 1, 3. 0, 1, 2, 3. So if we cut this part, then what should be the result? Like, this becomes— let's copy this. Um, so we are cutting this guy, right? So this supposed to become 0, this should be 0, this should be 0, this should be 0. Does it make sense?
Stealthy Elephant: Yes, I see where you're going with this. I see. Yes, that makes sense. Just make sure you keep track of it and don't get confused with the Z's you're putting in.
The Mighty Pumpkin: Z's my what?
Stealthy Elephant: You're putting Z, right? That's less— I'm assuming that's the value that you're replacing.
The Mighty Pumpkin: Like it will become 0?
Stealthy Elephant: Yeah.
The Mighty Pumpkin: And this is where we cut it, so this also becomes 0 at the end. But rest of the tree remains intact is what the intent is.
Stealthy Elephant: Okay, yeah, that sounds good.
The Mighty Pumpkin: Okay, now first, I guess the problem is given the cut points, we need to know which tree it's going to affect. Can it affect multiple trees?
Stealthy Elephant: Uh, yes, but for this example, you know, for the sake of the question, how would it look like after cut 1, 3?
The Mighty Pumpkin: This one. This is, this is what I mean to say, like on 32, 35, this is the output if we cut on 1, 3.
Stealthy Elephant: Yeah, okay, sure.
The Mighty Pumpkin: Uh, is it clear?
Stealthy Elephant: You are, uh, you are missing one thing. Why, why is this removed?
The Mighty Pumpkin: So if we cut this— oh, oh, because it's connected from here, so we remain, we leave it, huh?
Stealthy Elephant: Sure, yeah.
The Mighty Pumpkin: And if this would have not been connected, then we have to make it 0.
Stealthy Elephant: Yes, correct.
The Mighty Pumpkin: Like for example here, if, if this would have been 0, then if we cut at 1, 3, then this also goes away.
Stealthy Elephant: Yeah, right.
The Mighty Pumpkin: I see. Interesting. Okay, so given the point cut, I guess first thing I need to know is which tree it is. Or do I? Let's say I find the tree, and then if I figure out this is the cut point, um, then how do we decide we can cut it? Like, basically the question is we want to know if this particular point becomes 0, which all points can be converted to 0. And the property is this 0—
Stealthy Elephant: Okay.
The Mighty Pumpkin: It kind of feels like an expansion problem, so I'm thinking from a BFS perspective, like if, if that point is 1, 3, all you want to do is we want to expand from 1, 3 to all the ones connected to it. And, and see, um, so expand in 4 directions from cut land 101 If that one is connected to any other one, then don't make it 0. But that doesn't work because, like, in our first iteration, we have just made this one 0. And when we come to the next index on 1, 4, it will see 1, 5 is 1. So we cannot say for surety, we cannot say that this can become a 0. And I already confirmed like 1, this cannot be a part of another tree, or can it? Like, for example, like can there be a scenario like this where, like, this whole last column is a tree on its own, but it is connected to this other tree as well? Is it possible?
Stealthy Elephant: Yes. Huh? So say again, what was the example you provided?
The Mighty Pumpkin: So I just modified our Give an example. Um, so if you see on line 28, okay, can I make the last column 1? So now this whole last column is a tree in its own, but it is also on row 1. It is in a way connected to like—
Stealthy Elephant: Okay, and what's the cut? What's your cut value? 1, 3?
The Mighty Pumpkin: 1, 2. So 1, 2.
Stealthy Elephant: If we cut here, that's, that's 1, 3. 0, 1, 2, 3, right?
The Mighty Pumpkin: Yeah, the given example. So on line 36, we take cut.
Stealthy Elephant: So if you do this, uh, I mean, what do you think it is?
The Mighty Pumpkin: So if we do this, then the end value Will be this. So only one point becomes 0.
Stealthy Elephant: Yeah, yeah, I agree.
The Mighty Pumpkin: Okay, so that's— that makes it harder in a way because, because now this particular one Okay, like on row 1, comma, 4 is a part of 2 trees.
Stealthy Elephant: Yeah, but I don't think that should make— that shouldn't be a problem, right? Because, you know, you— one of the biggest hints that it gives you is that the tree always has a root, right? So even if it's A separate tree, it should not affect you if there's more than one tree.
The Mighty Pumpkin: Yeah, like in case of BFS, yeah, that's true. Like, I will have to figure out whether this particular 1, 4 is connected to any other tree or not, right? Because just the one nearby doesn't make any difference, because if 2, 4 or 2, 5 was 0, then 1, 5 is supposed to be 0 at the end. Uh, okay, so with BFS it's hard to tell. If we do DFS from every point

Like, ultimately I want to find which cut point is for sure known, so that becomes 0. And then I will scan for all the points which are 1 connected to this cut point. Okay, so find So the steps are cut becomes 0, expand in all 4 directions. If neighbor is 1, then it becomes 0. When if that one is not connected to any other tree, if that one is not connected to any other branch. Which won't be 0. Uh, okay, which won't be 0. Okay, so to find these 2 conditions needs to be false, then only I can mark that as 0. Okay, so just the case. If that is the case, I need to remove this point. Then you go here, but then you will see it's incoming from here as well. So I cannot set it to 0. Okay, if I was thinking from the adjacency list perspective, it's good because this point has a connection to the left and the right, and the left becomes 0. Does it have any other connection? Okay, I cannot count. Oh God. Okay, so it just says the list doesn't give me anything. What else can we do? We can do union find and we can connect all the ones together, but that doesn't tell If it's a separate tree. Okay, no, I think there is more information missing that I need to first collect before making a decision. Uh, what else? You cut point here, and then you figure out what are the. Okay, one thing. is true that whenever I'm trying to set any point to 0, Mm-hmm. if I do a DFS from that point and I'm able to reach the root or ground, then I cannot set it to 0. It means it is connected to ground from some other path. Yeah, so in our example, if I set 1, 3 to 0 first and then move to its neighbor— so let's say the neighbor is, you know, 0, 3— I do a DFS, and by doing DFS, I will reach row 3. It means I cannot set it to 0, and then I'll start from here, the next neighbor, and I cannot reach root because, because this— these, these paths cannot take it to root again. Uh, so we set it to all to false while the DFS is returning. Yeah, so we'll do a DFS from every point after cut point and keep setting these to 0 if they cannot reach the ground. If they can Then they cannot be set to 0. Um, yeah, does this sound correct?
Stealthy Elephant: Yeah, sounds good.
The Mighty Pumpkin: Okay, so we accept a grid, do a DFS from x, y And it is done, so I go and let's see it.
Stealthy Elephant: I'll be back in 10 seconds, okay? Just keep typing.
The Mighty Pumpkin: Okay. So we go to the neighbor and then to DFS. Okay, and do I need to do anything? Okay, and we'll modify the grid in place. What's gonna happen is when EDFS if— sorry. So the base condition is if x becomes the grid— or wait, sorry, x should be— um, so confusing a little. Oh, but great point is I'm— okay. Yeah, that makes sense. So grid, the lowest row is the ground, so that's fair. Otherwise, you go in— Okay, so you again do the same. You do the same if n is If it is a valid location, you keep going, um, you keep going DFS, and if it returns true Sorry, if it not returns true, then you set to 0, else you don't need to care. And you also check Only if it is 1, then we need to check, right? So we go keep doing that. And since we are only calling valid locations, uh, okay. And the fallback is Um, no, that's not right. Okay, so if we reach the end That's a true condition. But what's a false condition now? We are doing a DFS and we also need a visited set. And we only do DFS if we have not visited these points. Uh, that's fair. So avoiding cycles. Now the condition is still missing. Um, I reached the end, that's okay, but if we never reach the the end, which is— let's say we come here and there is nowhere to go. That's a false. Okay. But if it is a true, it is possible that we reached So it is possible in this depth we reached this point.

And if we have ever reached the end, from this point, we just return true. And it's possible there is nowhere to go from a point, so in that case we return false. It's fair. Oh, and actually you also need to check you reached the ground, but that ground needs to be Okay, okay, so we reached the ground. That's okay. Okay, but y should be valid, which will be valid. We are only calling valid-wise, and it should be a 1. That's when we say it is a tree.

Well, which will be 1 because we are always checking for 1 here. So yes, not needed. Okay, okay, I think based on the time we have, it should be fine.
And then yeah, I'm just doing 4 directions from the cut point. I don't think I have to do more.
Okay, that's good. What do you think? Is it going in the right direction? This is— that's our example. I don't know why it's not happy. Here you go. Uh-oh. Mx and y not in visitor.in, I think. Oh, another thing I missed. How to check the direction? Oh, same problem. Oh, it's here.

Stealthy Elephant: Just a quick heads up, I'll give you another minute and a half.
The Mighty Pumpkin: Okay, um, I just take the cut point and I'm going in all directions. Directions seems fine. I calculate an x and y. Okay, so it is looping here.
Um, we don't ever go here. We are catching and then we are going in all directions from the cut point. We have added the cut x Put y into the visited set. Then we start in all directions, we get the new neighbors using the direction. And if it is valid, which is where 1, 3 is the starting point, so it keeps looping to start. That's so weird. Because we've already added it to the visited.

Stealthy Elephant: Um, we do have to wrap it up.
The Mighty Pumpkin: Yes, that's okay.
Stealthy Elephant: Yeah, but some quick things before we finish it up is that I think some—
The Mighty Pumpkin: let me see, let me see.
Stealthy Elephant: Yeah, I'll put in the feedback section. I just want to give you the overall feedback. And then in terms of specifically for this question, I can give it to you in the written part. But give me one second, let me just put in the section here. So, so usually I break down this feedback into 4 areas: strengths, room for improvement, what you can do differently in the next interview, and open notes. So in terms of strengths, I would say at least for the first For both questions, you were able to understand what the question is asking, and you were able to narrow it down and ask more questions throughout the whole time. All right. And I would say you got the solid direction, you had the solid pacing, and you were able to go in, and you had a solid approach. Even for the first question, you had the brute force and you were able to do it, and you realized that there's got to be a more efficient solution to it. And you were able to go through it, and then I think you were able to solve it pretty fine. And then for the second question, I think that's where the hiccup comes, where you have the right direction. I think it's a little bit— I think that maybe the syntax-wise or the overcomplication of it. I think just doing more practice with BFS, DFS, and this recursion. I think you had a few bugs. I see a few bugs off the bat. I think it's, it's doing more questions, doing more DFS/BFS. I think you're slowing down and communicating while you're talking. I'm sorry, communicating while you're coding, right? So maybe there's some times where if you have a question, feel free to ask me, right? I think that's one thing. Another thing for improvement is for— I think you already got the— I already think you got the question already. I already think you got a solid idea of what you have to do for the question. But I don't think you need to ask, for example, in the very— for the second question, when you were able to get the whole example, you had many clarifying questions, but I think you already got it the first time. You already knew what you had to do after you gave— So for example, if I'm looking at This right here, which is this example, line 29. I know that you already knew the solution, but I know you were like, oh, what, what would the solution be if we did this, right? What would be the solution if we did this and that? I think that's good, right?

The Mighty Pumpkin: Oops, sorry.

Stealthy Elephant: I think that would be good, but I think after you got the first example, I think you had a very solid grasp. I think you could get started right away. No need to ask deal with the edge cases at the very end, right? Because if you can't solve the question and you deal with the edge cases first, then I think it would be a waste, right? So I would say, yeah, so I would definitely say that, you know, definitely do, you know, ask more questions about edge cases later, because I think as soon as you get the first example down, you were able to dive into the algorithmic section of the part. In terms of What you should do differently in the next interview is just— I think you could have finished it a little faster. I think leave the edge case question at the end. As soon as you get one example, start coding, start getting it. Like, you know, you can ask one more clarifying question, but if you feel like you know 95%, you can ask the interviewer, hey, does it look good? Is my logic correct? And then just get started so that you can fix it up later. And then another thing is, I think just communicating more while you're coding it. Right, and there were some times where I felt like I'm not sure you're asking a question or not, but always feel free to do like a check-in with the interviewer. Like, hey, am I doing okay? Is it in the right direction? So it gives you like a little bit of pulse check and make sure you're kind of working with the interviewer themselves. In terms of open notes, like the most crucial response is just doing many questions, but the structure I have is, for example, the first question you were able to do well. I think the second question where you had issues with, so I would just advise you to do more DFS, BFS recursion questions, and just do 2 or 3 questions a day, right? But then every time when you do a question, you redo it 3 days later, right? So every Sunday you redo all the questions that you've done, okay? And what would be really good is to make sure you finish the question under 10 minutes. That doesn't mean you have to code up everything. That's more like making sure you understand what the flow is, what you have to do, what's needed. Is there a set involved? Is there DFS or BFS involved? Is there recursion involved? I think that would be your best bet to really go inside this approach.