← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Meta coding round, tree problem that looked familiar until it wasn't. The twist on the classic right side view question tripped me up a bit.

Questions Asked (1)

Q1

Given the root of a binary tree, return the nodes visible from the right side and the nodes visible from the left side, both ordered from bottom to top.

Algorithms & Data Structures
Author's notes

I recognized the right side view part immediately and started coding before fully reading the prompt.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use BFS level-order traversal to record the first and last node at each level, then reverse the collected lists to get bottom-to-top order. Alternatively, use DFS with depth tracking to update leftmost and rightmost nodes per level, then reverse. Clearly state time and space complexity and handle edge cases like an empty tree.

Pro tip: Mention that you can combine both left and right views in a single traversal to save time, and discuss how you'd adapt the solution if the tree is very deep (e.g., iterative BFS to avoid recursion stack overflow).

1. Clarify the problem and edge cases

Confirm that 'visible from the right/left' means the rightmost/leftmost node at each depth, and that output should be bottom-to-top. Ask about empty tree, single node, and whether nodes can have duplicate values.

2. Choose traversal strategy

Decide between BFS (level-order) or DFS (pre-order with depth). BFS naturally gives level-by-level access; DFS can be more space-efficient for skewed trees. Explain your choice.

3. Collect leftmost and rightmost nodes per level

During traversal, record the first and last node encountered at each depth. For BFS, the first node in the level queue is leftmost, the last is rightmost. For DFS, update leftmost when visiting a depth for the first time, and rightmost whenever you visit a node at that depth (since pre-order visits rightmost last).

4. Reverse to bottom-to-top order

After traversal, reverse the lists of leftmost and rightmost nodes to satisfy the bottom-to-top requirement. Alternatively, build the lists by prepending, or traverse levels in reverse if using BFS with a stack.

5. Analyze complexity and test

State time complexity O(N) and space complexity O(N) for storing results (or O(H) for DFS recursion stack). Walk through a small example to verify correctness, including edge cases.

Key Points to Mention

  • BFS level-order traversal to easily identify first and last nodes per level
  • DFS with depth tracking as an alternative, noting space trade-offs
  • Handling empty tree and single-node tree gracefully
  • Time complexity O(N) and space complexity O(N) (or O(H) for DFS)
  • Reversing the collected lists to achieve bottom-to-top order
  • Combining both views in one traversal to optimize

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