Go Interview with a LinkedIn engineer.

Go Interview with a LinkedIn engineer

Watch someone solve the falling leaves of a tree problem in an interview with a LinkedIn engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.

Interview Summary

Problem type
Falling leaves of a tree

Interview question

  1. Given a list of numbers and a target, find if there exists a difference of two numbers that makes the target.
  2. Find how many ways there are to get from the top-left to the bottom-right of a grid only traversing down and right.
  3. Return a list of list, where each list is a layer of leaves. After those leaves are accounted for, imagine that they fall off and the next level up is now a layer of leaves.

Read more about the questions

Interview Feedback

Feedback about Neuro Owl (the interviewee)

Feedback about Existential Crumpet (the interviewer)

Interview Transcript

Neuro Owl: Hello?
Existential Crumpet: Hey.
Neuro Owl: Hey, Sorry, I'm a little bit late.
Existential Crumpet: No worries.
Neuro Owl: How you doing?
Existential Crumpet: Good, how are you?
Neuro Owl: Good. Where are you calling from.
Existential Crumpet: Seattle. Where are you?
Neuro Owl: I'm from San Francisco, right now.
Existential Crumpet: Alright. So, do you have anything in particular you want to practice?
Neuro Owl: Well, I'm preparing for a Google and Facebook interviews, so if you know what kind of phone interviews they have, that would be great.
Existential Crumpet: Okay. So I work at LinkedIn. I can give you questions of similar difficulty. I know that GeeksForGeeks has really good questions and then they list off questions by company. So I can do some Google or Facebook questions.
Neuro Owl: Okay, yeah, that sounds good.
Existential Crumpet: Cool. Alright. What would you the difficulty level you are going for here? I don't want to give you anything too easy, doesn't make very much sense.
Neuro Owl: Probably medium is good. Yeah, the medium is fine, probably. Yeah.
Existential Crumpet: Alright. Let's do this one. This one's hard. Alright, here's a medium. Alright. So. I don't know Go syntax, so I'm just gonna comment. So I'm gonna give you an array. It's gonna look like something like this. It looks kind of like that and then I'm also going to give you a number. I'd like for you to write a function that determines two numbers in the array that when the first number is subtracted by the second number equals the number I provided.
Neuro Owl: So subtract the first one from the second one. And return what the index is or...?
Existential Crumpet: The numbers themselves are fine.
Neuro Owl: Okay, all right, cool. So. Um, well, I could just walk the array and then compare each number to... well not compare, but try to match the numbers one to another, and then if I find a pair, I just print them or return them. That would be a quadratic because I'll have to compare each number to the rest of the numbers, basically like a double for loop. To do the faster, I could... Just walk the array and then kind of keep track of what I've covered so far with a hashmap, of them consult a hashmap for each next number and and see if there is a match. So, I'll probably go with that so that, that's going to be a linear time. Is that okay? Alright. Yeah, go ahead?
Existential Crumpet: Yeah, so. Why don't you do that. I can ask a follow up question after it.
Neuro Owl: Okay, cool. So I know you said you don't know Go syntax, but it's somewhat C like, so should be pretty straightforward. Alright, so I'm gonna create a hashmap of an integer to an integer, what I'm gonna keep probably gonna in the map, the key is gonna be the value of the item in there and then the value is gonna be the index at which the number is at. So when we try this... Obviously the main function... we'll write an actual function. And it doesn't matter if we didn't find anything. Let me see how should I do this? Oh and the target number, that's right. And you said subtract first one from the second one, right?
Existential Crumpet: Yeah, I mean, the order that you return them should be such that A minus B equals the number provided.
Neuro Owl: A minus B, okay got it. Alright, say difference is going to be... I think the number itself should be inserted there. Yeah, well index would be... So that should work. I can don't want to modify the input tree whatsoever. If we could just kind of cut off the leaves that fell, that would be easy.
Existential Crumpet: We could pretend that we're cutting them off because really there's nothing...
Neuro Owl: Right. Okay. So we need to do the leaves first. Alright, well. So we can easily get to the leaves recursively and just collect them all once we get to a node that doesn't have any left or right children. We added to some list. But... But at that point we'll traverse the whole tree already. And then after that we need to get to the rest.