← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Meta coding round, tree problem that looked straightforward until the indentation part threw me off a bit. Variant of a classic problem but with enough of a twist to keep you honest.

Questions Asked (1)

Q1

Given the root of a binary tree, print every root-to-leaf path such that each node in the path is indented based on its column position (left children decrease the column offset by one, right children increase it by one).

Algorithms & Data Structures
Author's notes

I knew it was a DFS path problem the second I read it, but the indentation requirement made me second-guess my approach for a minute.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a depth-first search (DFS) traversal that tracks the current path and column offset for each node. When a leaf is reached, print the path with each node indented by its column offset relative to the root. Handle negative offsets by shifting all indentation by the minimum offset encountered.

Pro tip: Clarify with the interviewer whether the indentation should be relative to the root (column 0) or normalized to avoid negative spaces. Mention that you can compute the minimum column offset during traversal and shift all offsets accordingly, showing attention to edge cases.

1. Understand the problem and constraints

Confirm that each node's column is determined by its position relative to the root: left child decreases column by 1, right child increases by 1. Ask about output format and whether negative columns are allowed.

2. Choose traversal strategy

Select DFS (recursive or iterative) to explore all root-to-leaf paths while maintaining the current path and column offset. Explain why DFS is suitable for path-based problems.

3. Track path and column offset

During traversal, maintain a list of nodes in the current path and their column offsets. When a leaf is reached, record the path and offsets for printing.

4. Normalize indentation

After collecting all paths, find the minimum column offset across all nodes to shift offsets so that the leftmost node starts at column 0. Alternatively, compute the shift on the fly if possible.

5. Print formatted paths

For each root-to-leaf path, print each node's value preceded by spaces equal to its normalized column offset. Ensure proper alignment and separation between paths.

Key Points to Mention

  • DFS traversal to explore all root-to-leaf paths
  • Maintaining current path and column offset during recursion
  • Handling negative column offsets by normalizing indentation
  • Time and space complexity: O(N) time and O(H) space for recursion stack, where N is number of nodes and H is tree height
  • Edge cases: empty tree, single node, skewed tree
  • Output format: each path on a new line, nodes indented by column offset

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