Hi, here’s your problem today. This problem was recently asked by Uber:
Given a binary tree, and a target number, find if there is a path from the root to any leaf that sums up to the target.
Here’s an example and some starter code.
class Node: def init(self, value, left=None, right=None): self.value = value self.left = left self.right = right
def target_sum_bst(root, target):
Fill this in.
n6 = Node(6) n4 = Node(4) n3 = Node(3, None, n4) n2 = Node(2, None, n6) n1 = Node(1, n2, n3)