List the Rightmost Visible Node at Each Depth of a Tree

Last updated: November 29, 2026

Quick Overview

Picture a binary tree of UI elements drawn top to bottom. Return the value of the node you would see at each depth when looking from the right side.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Picture a binary tree of UI elements drawn top to bottom. Return the value of the node you would see at each depth when looking from the right side.

A level-order traversal question in the style of Microsoft technical screens. Interviewers check that the candidate knows the rightmost node at a depth may sit in the left subtree, and can solve it with both BFS and DFS.

What the Interviewer Expects
  • Recognize that the answer is the last node of each level
  • Use BFS processing one level at a time
  • Handle nodes that appear only in a left subtree
  • Offer a DFS alternative that visits right before left
  • Return values top to bottom
Key Topics to Cover
binary trees
breadth-first search
level-order traversal
DFS
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the left side view as well, with one traversal.
  • Return the full boundary of the tree in counter-clockwise order.
  • How would the DFS version behave on a very deep tree?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: root of a binary tree.
  • Output: list of values, one per depth, the rightmost node at that depth.
  • Empty tree gives []....
High-Level Design

Do BFS with a queue and process exactly len(q) nodes per round; the last node popped in that round is the rightmost at that depth. A common mistake is to follow only right children: in a tree where ...


Submit Your Answer
Markdown supported