Given a binary tree, check if there are three elements in binary tree which will sum up to zero. Return true if triplet exists, if not return false.
For example:
4
2 6
-5 3
In this binary tree, {-5, 2, 3} sum up to zero and you should return true.
0
-1 1
In this binary tree, {-1, 1, 0} sum up to zero and you should return true
1
-1 2
In this binary tree, there doesn't exist a triplet that sum to zero and the result should be false.
Your Answer.java should implement the following interface,
public interface TripletSummingToZeroInterface {
public boolean doesTripletSumToZero(Node root);
}
Node.java (No need to submit this, just for reference)
public class Node {
public int nodeValue;
public Node lChild;
public Node rChild;
}
Answer
Answer
No comments:
Post a Comment