Sobes.tech
Junior — Middle+

List of nodes visible from the right side of the binary tree

livecode

Task condition

Given the root of a binary tree. Imagine you are looking at the tree from the side, from the right. You need to return an array of the values of all the nodes that are visible from this view, ordered from top to bottom.

Example tree:

      3
     / \
    1   4
   / \   \
  0   2   5

Answer: (3, 4, 5)