Problem: Given a binary search tree, please check whether there are two nodes in it whose sum equals a given value.
| Figure 1: A sample binary search tree |
For example, if the given sum is 66, there are two nodes in Figure 1 with value 25 and 41 whose sum is 66. While the given sum is 58, there are not two nodes whose sum is same as the given value.
Read full article from Coding Interview Questions: No. 46 - Nodes with Sum in a Binary Search Tree
No comments:
Post a Comment