FastPrepBinary Tree Right View
Problems/Binary Tree Right View

Binary Tree Right View

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source names the conventional Binary Tree Right View exercise but omits its interface, examples, and bounds. The judged task uses the standard top-to-bottom right-side-view result and matches the visible source at about 94%.

Given the root of a binary tree, imagine viewing the tree from its right side.

Return the value of the visible node at each depth, ordered from the root level downward. For an empty tree, return an empty array.

Function

rightSideView(root: TreeNode) → List<Integer>

Examples

Example 1

root = [1,2,3,null,5,null,4]return = [1,3,4]

The rightmost visible values at successive levels are 1, 3, and 4.

Example 2

root = [1,null,3]return = [1,3]

The right child is visible below the root.

Example 3

root = []return = []

An empty tree has no visible levels.

Constraints

  • The tree contains between 0 and 10000 nodes.
  • -10^9 <= Node.val <= 10^9.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> rightSideView(TreeNode root) {
      // write your code here
    }
}
Checking account…