# Python Interview with a Meta engineer

### Interview Summary

- **Problem type**: Minimum Depth of Binary Tree
- **Interview question**: 1) Given a binary tree, find its minimum depth.  
  The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Note: A leaf is a node with no children.

2) Given the root of a binary tree, the depth of each node is the shortest distance to the root.

Return the smallest subtree such that it contains all the deepest nodes in the original tree.
A node is called the deepest if it has the largest depth possible among any node in the entire tree.

The subtree of a node is a tree consisting of that node, plus the set of all descendants of that node.

### Interview Feedback

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

> Strengths & what went well:
> - Able to pseudocode multiple approaches and determine optimal solutions.
> - Understood OOP (Object Oriented Programming) principles in their language of choice (Python3).
> - Knows fundamental Binary Tree / Graph based algorithmic approaches / solutions (BFS / DFS) and when to use which one.
> 
> Areas for improvement:
> - Practice more recursive approach based algorithms, recursion can make straightforward logic get messy. Define your base case in all recursive approach based problems / solutions.
> 
> Advice for future interviews:
> - For Meta, be aware of the time you have left and make your intros concise to leave you more time for solving potentially 2 questions.

**Interview Transcript**

**Diamond Pterodactyl**: I have an interview with Meta tomorrow. It's the initial phone screen. The format they mentioned was you basically solve two roughly leetcode mediums in 45 minutes. So I just kind of want to benchmark against that to see or even just get used to that type of format. I have about seven years of software engineering experience, mostly in back end infrastructure.

**Clandestine Snake**: A little tougher, but that's fine. Let's do this. I'm gonna paste this question. I want to see if you have seen this before.

**Diamond Pterodactyl**: Okay.

**Clandestine Snake**: A little tougher, but that's fine. I'm gonna go ahead and comment this out and then here we go.

**Diamond Pterodactyl**: Given the root of this, I'm going to read out. I'm going to read it quietly. The depth of each node is the shortest distance return us return the smallest subtree such that it contains all the deepest nodes in the. Okay, let's call the deepest. If it has the. Okay. I have not seen this problem before, so I'm happy to solve it. And great.

**Clandestine Snake**:  Before we solve this though, it's great that you didn't see this before.

**Diamond Pterodactyl**: So here you go. Okay. Given the minority, find its minimum depth. The depth is the from the root down to the nearest leaf node. A leaf node is no children. Okay, I'm ready to start talking and working through this problem. If this is the format, which I think it is. So to me, this is a pretty straightforward problem either when I'm thinking about trees, I can think about dfs. Dfs, we're looking for the minimum depth number of nodes along the shortest path from the root to the two little beaks node. So if I have a tree that is like this, sorry for the formatting, the minimum depth. Okay, so in this case the minimum depth would be two, right? Because there's three and two. And if I add this, if I add one more, this would be, this would be. The minimum depth would be three. Is that, is that understanding correct?

**Clandestine Snake**: Yep.

**Diamond Pterodactyl**: Cool. Finding the minimum depth. I guess one approach is to basically find. One approach is to find the depth art, traverse the entire tree keeping track of depth and you know, have a separate variable keeping track of minimum, minimum, minimum depth.

**Clandestine Snake**: So that approach that you just mentioned, which one is that? Is that BFS or dfs?

**Diamond Pterodactyl**: Oh, when I walked through it, I was using dfs. So I start, go down, go down.

**Clandestine Snake**: And then. So a DFS approach would be.

**Diamond Pterodactyl**: Oh, when I walked through it, I was using dfs.

**Clandestine Snake**: Okay, great question and build up of questions. Good proctoring of interview to be similar to that of Meta. I kind of got lost with the hints to the problem. Not sure if that's because I was too constrained in thinking about LCA for two nodes.

**Diamond Pterodactyl**: Yeah, yeah, for sure. Mapping through responses to make sure we're being clear. I could either try to code this or...
