Grokking Data Structures & Algorithms for Coding Interviews
0% completed
Stretch Problem: Binary Tree Right Side View (medium)
This problem is optional. The problems above cover what the chapter teaches. This one is here for readers who want a harder tree question, and nothing later in the course depends on it.
Problem Statement
You are given the root of a binary tree. Imagine standing to the right of the tree and looking at it. Return the values of the nodes you can see, ordered from the top down.
A node is visible when it is the rightmost node on its level.
Examples
Example 1
- Input: root =
[1, 2, 3, null, 5, null, 4] - Expected Output:
[1, 3, 4]
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%