Medium Accuracy: 47.17%
Submissions: 30068 Points: 4
Given a Binary Search Tree and a target sum. Check whether there's a pair of Nodes in the BST with value summing up to the target sum.
2 / \
sum = 5
Nodes with value 2 and 3 sum up to 5.
1 4sum = 2
There's no pair that sums up to 2.
You don't need to read input or print anything. Your task is to complete the functionisPairPresent() that takes a root node and a target value as a parameter and returns 1 if there's a pair of Nodes in the BST with values summing up to the target sum, else returns 0.
Expected Time Complexity: O(N). Expected Auxiliary Space: O(Height of the BST).
1 ≤ Number of Nodes ≤ 105
1 ≤ Sum ≤ 106