Challenge: Sum of All Nodes in a Binary Tree

Let’s calculate the sum of the values present in the binary tree.

Problem

Given a binary tree, find the sum of values of all its nodes.

Input

A binary tree.

Output

Sum of values of all the nodes.

Sample input

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.