Goldman Sachs Interview Question
633 Interview Reviews |
Back to all Goldman Sachs Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Analyst at Goldman Sachs:
1)find a value in BinarySearchTree, 2)Print elements in level order 3)diff between set, list
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (2)
public void printTreeInOrder(Tree t)
{
Queue<Tree> q = new Queue<Tree>();
if (t!=null)
{
q.offer(t); //push tree to the queue
}
printTreeHelper(q);
}
public void printTreeHelper(Queue<E> q)
{
if ((Tree t = q.poll)!=null)
{
system.out.println(t.val);
q.offer(t.left); //push left son
q.offer(t.right) // push right son
printTreeHelper(q); //recursive call
}
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Dan:
find a value in a binary search tree
public boolean isValueExist(Tree t, int val)
{
while (t!=null)
{
if (t.val == val)
{
return true;
}
if (t.val >= val)
{
t=t.left
continue;
}
t=t.right;
}
return false;
}