| Topic | Difficulty | Companies |
|---|---|---|
| Binary Tree | EASY | Amazon Microsoft Yahoo |
Given the root node of a binary tree and a sum, write a program to determine if there exists a path in the tree from root-to-leaf such that the sum of all the values along the path equals the given sum.
Problem Note
Example 1
Input: Given the below binary tree and sum = 22
6
/ \
4 8
/ / \
10 14 3
/ \ \
8 2 1
Output: 1
Explanation: There exist a root-to-leaf path 6->4->10->2 which sum is 22 so output is true i.e. 1