Mark As Completed Discussion

Good evening! Here's our prompt for today.

A binary search tree is a data structure that has the following properties,

  • Each node in the tree has only two children.
  • The left subtree consists of nodes with values less than the root node.
  • The right subtree consists of nodes with values greater than the root node.

Consider a binary tree with the root node given as root. Your task is to return the values of the nodes that are on the right side of the binary tree, ordered from top to bottom.

Question

For example, consider the tree in the image above. On the right side of the tree, we see the values 9, 11, and 16. These are returned as an array [9, 11, 16].

Constraints

  • The number of nodes in the tree is in the range [0, 100].
  • 100 <= Node.val <= 100

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's our guided, illustrated walk-through.

How do I use this guide?

Access all course materials today

The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

Returning members can login to stop seeing this.