← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Meta SWE interview that centered on binary tree traversal, specifically getting both the left and right side views in one problem. The discussion portion about BFS vs DFS tradeoffs is where I felt the most pressure.

Questions Asked (1)

Q1

Given the root of a binary tree, return the values visible from the right side and the left side when looking at the tree top to bottom. Then walk through the tradeoffs between a level-order BFS approach and a depth-first approach that tracks node depth.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went straight to BFS because keeping track of the last (or first) node per level felt clean and obvious.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: the right-side view is the last node at each depth, and the left-side view is the first node at each depth. Then present a level-order BFS solution that processes nodes level by level, capturing the first and last nodes per level. Finally, compare it with a depth-first approach that tracks the first and last node seen at each depth, discussing tradeoffs in time, space, and code complexity.

Pro tip: Mention that both approaches are O(n) time, but BFS uses O(width) space while DFS uses O(height) space; for a balanced tree, BFS is O(n) space, whereas DFS is O(log n). This shows you understand practical memory implications.

1. Clarify the problem

Confirm that the right-side view consists of the rightmost node at each depth, and the left-side view consists of the leftmost node at each depth. Ask if the tree can be empty or if nodes have unique values.

2. Present BFS solution

Use a queue to perform level-order traversal. For each level, record the first node's value for the left view and the last node's value for the right view. Continue until the queue is empty.

3. Present DFS solution

Use preorder traversal (root, left, right) to capture the left view by recording the first node seen at each depth. For the right view, use a modified preorder (root, right, left) to record the first node seen at each depth.

4. Compare tradeoffs

Discuss time complexity: both are O(n). Space: BFS uses O(width) for the queue, DFS uses O(height) for the call stack. Mention that BFS naturally gives level-by-level access, while DFS may be more memory-efficient for deep, narrow trees.

5. Summarize and conclude

State that both approaches are valid, and the choice depends on the tree shape and memory constraints. Emphasize that DFS can be more space-efficient for balanced trees, while BFS is simpler to reason about for level-based views.

Key Points to Mention

  • Right view = last node at each depth; left view = first node at each depth.
  • BFS uses a queue and processes level by level, naturally capturing first and last nodes.
  • DFS uses recursion (or stack) and tracks depth to record the first node seen at each depth for the desired view.
  • Time complexity is O(n) for both; space complexity is O(width) for BFS and O(height) for DFS.
  • For a balanced tree, BFS space is O(n) while DFS space is O(log n); for a skewed tree, BFS space is O(1) while DFS space is O(n).
  • DFS can be adapted to capture both views in a single traversal by tracking both first and last nodes per depth.

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