Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Binary Tree Right Side View

Medium
treebinary-treebfsdfs

Standing to the right of a binary tree, return the values you can see from top to bottom (the rightmost node of each level).

Input: one line — the tree in level order. Output: the visible values, space-separated (nothing for an empty tree).

Example 1
Input:
1 2 3 null 5 null 4
Output:
1 3 4
Example 2
Input:
1 null 3
Output:
1 3

Constraints

  • 0 ≤ nodes ≤ 100
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.