PREP65 Editorial

Problem Explanation

We are given a binary tree and we have to tell if the sum of all the values in the path from root to any one of the leaf nodes is equal to exactly K.

Approach

We apply DFS traversal on the binary tree and send the remaining K after subtracting the values of the traversed nodes. At each leaf node we can check if remaining K is equal to the data of that leaf node. If it is, then the path from root to that leaf node sums to exactly K.