Binary Tree Right Side View

Trees: DFS & BFS, problem 5 of 8

Binary Tree Right Side View

Medium

LC #199

bfsdfs

Not attempted yet

Imagine standing to the right of a binary tree. Return the values you can see, from top to bottom: the rightmost node of each level.

Example 1

Input: root = [1, 2, 3, None, 5, None, 4]
Output: [1, 3, 4]

Example 2

Input: root = [1, 2, 3, 4]
Output: [1, 3, 4]

Level 3 only has 4, on the left, but you still see it.

Example 3

Input: root = []
Output: []

Constraints

  • 0 ≤ number of nodes ≤ 2 · 10^4
  • -10^5 ≤ Node.val ≤ 10^5

Python

Loading draft…

Test results

7 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 4 hidden

Run examples, then submit all tests.