← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE coding round, one question about printing a filesystem tree with indentation. Pretty clean problem but the details around formatting tripped me up more than I expected.

Questions Asked (1)

Q1

Given the root node of a filesystem tree where nodes are either directories or files, implement a function that prints the full directory structure with indentation markers indicating depth.

Algorithms & Data Structures
Author's notes

Recursive DFS was the obvious move and I went there immediately, which was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the node structure and output format, then implement a recursive DFS that passes the current depth to print each node with appropriate indentation. Discuss iterative alternatives and edge cases like empty directories or deep recursion.

Pro tip: Mention that recursion depth could be an issue for very deep trees and offer an iterative BFS/DFS with an explicit stack as a follow-up, showing you consider production constraints.

1. Clarify requirements and assumptions

Ask about the node class (children list, name, isDirectory flag), output format (indentation characters, sorting order), and whether to handle symlinks or hidden files.

2. Choose traversal strategy

Select recursive DFS for simplicity, or iterative DFS/BFS if recursion depth is a concern. Explain the trade-offs.

3. Implement the traversal with depth tracking

Write a function that takes a node and current depth, prints the node name with indentation, then recursively processes children with depth+1.

4. Test with edge cases

Walk through examples: empty directory, single file, nested directories, and a deep tree to verify indentation and order.

5. Analyze complexity and discuss optimizations

State O(N) time and O(H) space for recursion (H = height). Mention iterative alternative to avoid stack overflow.

Key Points to Mention

  • Recursive DFS with depth parameter for indentation
  • Time complexity O(N) where N is total nodes
  • Space complexity O(H) for recursion stack, H is tree height
  • Handling edge cases: empty directory, single node, deep tree
  • Iterative alternative using explicit stack to avoid recursion limits
  • Output formatting: indentation characters (e.g., two spaces or tabs) and sorting children if needed

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.