# Python Interview with a Meta engineer

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

Python interview with a Facebook engineer: Tree serialization - YouTube

### Interview Summary

**Problem type**  
Tree serialization

**Interview question**  
1) Write functions to serialize and deserialize a tree.  
2) Determine if two numbers in the list sum to a target number.

**Read more about the questions**  
- [Two Sum](/content/questions/two-sum/index.html)

### Interview Feedback

**Feedback about Kind Dragon (the interviewee)**  
**Advance this person to the next round?**  
Yes  
**How were their technical skills?**  
4/4  
**How was their problem solving ability?**  
4/4  
**What about their communication ability?**  
4/4

> Great job with the interview, I was really impressed by your performance! Summarizing some high-level feedback:  
> \* Loved that you explicitly wrote out the constraints, inputs, outputs, approaches, and test cases. This kept the interview very well-organized.  
> \* On the second problem. this is also another helpful similar practice problem and solution:  
>  \* https://leetcode.com/problems/continuous-subarray-sum/description/  
>  \* https://youtu.be/wsTcByj8QbI  
> Very small suggestion for improvement: after you finish writing code, make sure to let your interviewer know you are done with implementation before moving on to writing test cases (i.e. looking for corner cases).

**Feedback about Mechanical Llama (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

> I can't believe this is your first interview. Because you did it really great!

### Interview Transcript

Mechanical Llama: Hello.  
Kind Dragon: Hi.  
Mechanical Llama: Hi. Nice to meet you. Can you hear me alright?  
Kind Dragon: Yeah, I can hear you.  
Mechanical Llama: Yep. Cool. I'll just do a quick intro of myself. So yeah, I'm a senior engineer at a big tech company. And I've been doing interviews for a while now at my company. But I'm still kind of new to the interviewing.io platform. So if you have any feedback from me about the interview at the end, as well, I'd love to hear back from you. Yeah, if we can get the quick intro of yourself as well before we start.  
Kind Dragon: Okay. I am a senior engineer, too. I am a person that has more than 10 years of experience. And now I be leading the Google on site interview. Yeah.  
Mechanical Llama: Cool. That sounds great. So yeah. I guess before I get started, I also just wanted to share some interview logistics. And normally when I do interviews at my company, they're 45 minutes. So thinking, we could also like try to aim to finish this in 45 minutes, right. And then we can spend the last 15 minutes going over any feedback or questions?  
Kind Dragon: Yeah, sounds great.  
Mechanical Llama: Cool. Okay. So I'm actually going to open the drawing window for this problem. Okay. Yeah, yeah. So basically, what we're going to try to do is serialize and... we're going to write two functions. So one is the binary.  
Kind Dragon: I'm sorry, I'm sorry. There is a lot of echo. So I cannot have to catch your voice.  
Mechanical Llama: So is it better now?  
Kind Dragon: Can you use the headset.  
Mechanical Llama: Yeah. So I actually am using a headset. I can try to see if that helps. Great. Yes. Is it better?  
Kind Dragon: Yeah. Now we it's better.  
Mechanical Llama: Okay. Cool. Yeah, I think it is hard to understand later, you can let me know. Yeah, sure. Okay. Okay, cool. Yeah, so basically, what we're trying to do is serialize and deserialize, a binary tree. So for input, we have something let's take a second to write out an example tree. So we just have any like arbitrary tree, right? It doesn't really matter what's in it. So this is our tree. And what I want you to do right is write a function that given this tree class, or this tree representation, right? It comes up with so we have like a method called store which takes in the node, right, and then return some representation, right of the tree. And then we have restore, which takes should be list of nodes. Which takes this list and then returns the tree. And I think sorry, this is incorrect. Let me just rewrite this in actual Python syntax. Yeah. Yeah. So something like that is right. So we have two functions, one that takes in the tree representation. Returns a list of actually they should be list of ints and then one that takes in the list representation of the tree and then returns a tree class.  
Kind Dragon: Okay, cool. Okay. I think I understood the question. Before, start, I have some question. Okay. What is number of nodes?  
Mechanical Llama: Yeah, so that's a good question. You can assume that they all fit in memory. So okay, yeah.  
Kind Dragon: Minimum is zero, right. Okay. Cool. Continue, we're going to know what is the range of node values?  
Mechanical Llama: Yeah, that's a good question. So you can assume that they're all integers, but there could be negative values as well.  
Kind Dragon: So and in actually it can be from negative two to the 31... Yeah. Okay, cool. So okay, so okay maybe look at the root. Yes. Depart I think that our is the just the tree. So you need to be... Oh, root, we need to convert it to the list and then maybe pass the visual referencing yes and then next is we need to reach to exactly cool. Okay to serialize I think we need to use the DFS. So maybe we're gonna have to traverse in order and then we put the value one by one and that the time we need or so needed to prove node value. So, unfortunately integer we are able to print those values. So it is okay. So after that, maybe we could able to convert it to the list at this time. This time, time complexity is O(n). Okay. And space I think we are because we're gonna use the system stack of recursion. And then the worst case tree the skewed to the left side or right side, it will be because system stack will be the same as the depth of the tree. That make sense? Okay, now, think about this tour. This time maybe I think we also make the we also epic to restore with the clear path. It postorder so at this time time is linear and space is also linear. So make sense?  
Mechanical Llama: Yep, that makes sense.

---

**This part of the transcript continues to detail the interview process, including problem-solving discussions and feedback. Adjustments have been made to preserve coherence while excluding extraneous elements.**

---

Mechanical Llama: So. Yeah, yeah. So lets you execute. Okay. Yeah. So, okay. Yeah. So that and then, yeah no need to execute. But I think just before moving on to writing test cases, right? just kind of tell like alert your interviewer right, that, hey, I'm done with implementing, right. And now I'm going to write test cases, just so they know, like, what what's happening, right? Because otherwise, like, the interviewer might get distracted, right like while you're finishing the implementation and then not realize that you're moving on to test cases but that's okay.  
Kind Dragon: Okay, I have kept up because I have a past cases. So could you explain what these two test cases did is looking for the corner cases? Like?

---

Mechanical Llama: Thank you so much. It was really nice to meet you. And I wish you all the best. If you don't mind, I'm sharing my YouTube channel.  
Kind Dragon: Okay. definitely take a look at it and subscribe.
