836
0 Likes

DSA Crash Course [Part 43] - Tree Sum Approach

In this lesson, Alvin explores the strategy to solving the following interview problem:

Write a function, tree_sum, that takes in the root of a binary tree that contains number values. The function should return the total sum of all values in the tree.

a = Node(3)
b = Node(11)
c = Node(4)
d = Node(4)
e = Node(-2)
f = Node(1)
a.left = b
a.right = c
b.left = d
b.right = e
c.right = f

#