Find a path in a binary search tree which yields the sum equal to a given value X.

you are given a BST where each node has a integer value, parent pointer, left and right pointers. Write a function to find a path with a given sum value. Path can go from left subtree tree , include root and go to right tree as well . We need to find these paths also.

5
/ \

1    10
/ \    / \
0   2  6  11

so to find 16 we say it is 1 to 5 to 10.

Solution:

Unsolved but idea is to store the visited nodes and keep checking left and right.

Published by Jeet

A software developer by profession. In spare time, fancy non-fiction mostly, related to history, finance and politics. A self-proclaimed movie buff - genre, time and era is no bar, only a sumptuous movie is!

One thought on “Find a path in a binary search tree which yields the sum equal to a given value X.

Leave a comment