Path Sum (Binary Tree Root to Leaf Path Sum)

Binary Tree Root to Leaf Path Sum Equal to a Given Number.

Given a binary tree and a sum, Determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

If path is found then return true else return false.

Note: What is leaf node? Any node whose left and right children is null is known as leaf node.

For example –

In this Binary tree, there exist a path from root-to-leaf node whose sum is equal to the given sum (which is 16).

Now, suppose if the given value of sum is 12. Then in this case we simply return false. As the root-to-leaf node path does not exist in a Binary tree whose sum is equal to 12.

Right View of a Binary Tree

Given a binary tree, we have to write a code to print the right view of a binary tree.

Right View of a Binary Tree

The right view of a binary tree is the set of visible nodes when it is visited or seen from the right side.

For example:

Example 1:

Let’s take an example. In this binary tree, the node which is visible from the right side is 1, 3, 4, and 8.