# Print Folder Structure Problem (Python)

#### Watch someone print a folder structure using Python in a mock interview with a Google engineer. Explore this problem and others in the world's largest library of interview recordings.

### Interview Summary

**Problem type**  
Print folder structure  
**Interview question**  
Given a list of file paths, print all of the files in each of the folders.

### Interview Feedback

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

> I gave feedback verbally to the interviewee at the end of the interview. To recap, the feedback was:
>
> - Try to stay higher level before you jump in
> - Think about optimizations before you code
> - Code was very clean! Nice work. Clearly has great technical skills
> - Don't feel like you need to explain the entire time unless you like thinking out loud
> - Use small utility functions to save time. The interviewer likely won't ask you to implement if they are trivial, or at the very least won't dock marks if you run out of time without implementing.
> - Conversely, don't use too many util functions where you start to run out of time
> - Look for ways to simplify your solution

```python
class FilesystemNode:
    def __init__(self, name):
        self.name = name # string
        self.children = {} # {child1:.., child2:..}

def add_child_if_not_exists(self, child_name):
        if child_name in self.children:
            return None
        self.children[child_name] = FilesystemNode(name=child_name)

class Filesystem:

def __init__(self, files):
        self.trie = self._build_trie(files)

def pretty_print_dir_structure(self):
        self._pre_order_traversal(self.trie)

def _build_trie(self, files):
        trie = FilesystemNode(name='/')
        for file in files:
            current_trie_node = trie
            for file_path_element in file.split('/'):  
                new_child = current_trie_node.add_child_if_not_exists(file_path_element)
                if new_child is not None:
                    current_trie_node = new_child

def _pre_order_traversal(self, trie, num_tabs=0):
        for child in trie.children.values():
            self.print_with_tabs(child, num_tabs)
            self._pre_order_traversal(child, num_tabs + 1)
```

**Feedback about Astronomic Koala (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

**Interview Transcript**  
Astronomic Koala: How's it going today?  
Intrepid Broccoli: Good. How are you? Are you the Astronomic Koala? Interesting.  
Astronomic Koala: Yeah, that is very true. And I see you are Intrepid Broccoli.  
Intrepid Broccoli: That's right.  
Astronomic Koala: That's pretty funny because I'm eating broccoli like right now.

### Conclusion
- The interview aligned with expectations in technical assessment, showcasing the importance of structured problem-solving and optimization considerations.
