finished question4.1 with brute force method.Used ctci library to generate tree in order to test.So this code can only be tested in eclipse with ctci library