← Microsoft Interview Insights

Microsoft·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Microsoft SWE interview with a binary tree visibility problem. Pretty standard algorithmic round, nothing too wild, but the question had a couple of angles worth thinking through.

Questions Asked (1)

Q1

Given the root of a binary tree, return the node values visible from the right side, ordered top to bottom.

Algorithms & Data Structures
Author's notes

I went with BFS first since it felt safer to explain.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use BFS level-order traversal, recording the last node of each level. Alternatively, use DFS with depth tracking, updating the result when visiting a node at a new depth. Explain the chosen approach and its complexity.

Pro tip: Mention that BFS is more intuitive for level-based problems, but DFS can be more space-efficient for skewed trees. Also, clarify that the right view includes the rightmost node at each depth, even if it's not the right child.

1. Clarify the problem

Confirm that the right view consists of the rightmost node at each depth, and that the tree may be unbalanced. Ask if the tree can be empty or have only one node.

2. Choose an approach

Decide between BFS (level-order traversal) and DFS (pre-order with depth tracking). Explain why one might be preferred over the other.

3. Outline the algorithm

For BFS: use a queue, process each level, and add the last node's value to the result. For DFS: traverse right-first, track depth, and add the first node encountered at each depth.

4. Analyze complexity

State that both approaches have O(n) time complexity. Space complexity is O(w) for BFS (w = max width) and O(h) for DFS (h = height).

5. Handle edge cases

Consider empty tree (return empty list), single node, and skewed trees. Ensure the solution works for these cases.

Key Points to Mention

  • Level-order traversal (BFS) using a queue
  • DFS with depth tracking and right-first traversal
  • Time complexity O(n) and space complexity O(w) or O(h)
  • Edge cases: empty tree, single node, skewed tree
  • Difference between right view and right child
  • Potential follow-up: left view or boundary traversal

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