Binary Tree Right Side View Problem
Binary Tree Right Side View Problem — ExecCode Medium DSA Practice
Solve the Binary Tree Right Side View problem on ExecCode. Free online medium DSA practice in Tree. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given the root of a binary tree, imagine standing on the right side of it. Return the values of the nodes you can see, ordered from the top level down to the bottom level. Only the rightmost visible node of each level should appear in the result — nodes hidden behind a righter sibling are skipped.
Examples
Input root = [1, 2, 3, null, 5, null, 4]; Output [1, 3, 4]. Input root = [1, 2, 3, 4]; Output [1, 3, 4]. Input root = [1]; Output [1]
Constraints
The number of nodes is in [0, 100]. -100 <= Node.val <= 100
Practice Binary Tree Right Side View free on ExecCode. Browse DSA problems, topic map, and placement guides.