← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026Remote

Summary

Google SWE coding round, one tree problem the whole time. Pretty standard vibe but the follow-up on complexity tripped me up a bit.

Questions Asked (1)

Q1

Given a binary tree, return the values of the nodes visible from the right side, top to bottom. Explain your algorithm and its time and space complexity, using either BFS or DFS.

Algorithms & Data Structures
Author's notes

Went with BFS since level-order traversal makes it pretty natural to grab the last node at each depth.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then present a level-order BFS solution that records the last node at each level. Explain the algorithm step-by-step, analyze time and space complexity, and briefly mention an alternative DFS approach for comparison.

Pro tip: Emphasize that BFS naturally processes nodes level by level, making it intuitive to capture the rightmost node; also note that DFS can achieve O(h) space, which is advantageous for deep trees.

1. Clarify the problem

Confirm that 'right side view' means the rightmost node at each depth, and discuss edge cases like an empty tree or a tree with only left children.

2. Choose an approach

Select BFS for its intuitive level-order traversal, or DFS if space efficiency is critical; briefly justify your choice.

3. Explain the algorithm

For BFS: use a queue, process each level, and record the last node's value. For DFS: traverse right-first, tracking depth and updating the result when visiting a new depth.

4. Analyze complexity

State that both approaches run in O(n) time. BFS uses O(w) space (w = max width), while DFS uses O(h) space (h = height).

5. Discuss trade-offs

Compare BFS and DFS in terms of space usage, code simplicity, and suitability for different tree shapes.

Key Points to Mention

  • Level-order traversal using a queue
  • Recording the last node at each level
  • DFS with right-first traversal and depth tracking
  • Time complexity: O(n) for both approaches
  • Space complexity: BFS O(w) vs DFS O(h)
  • Handling edge cases: empty tree, skewed tree

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