Groupon Interview Question for SDE1s


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

You can send the tree as preorder and in order traversals or XML tree and then parse to reconstruct the tree.

- Expressions April 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Send binary tree as an array.

A binary tree can be put in the array very easily. child of nodes of "i" are located at "2*i" and "2*i+1". So just pass him as a stream of numbers starting from the array index 1. You have to send the first number to be the number of nodes in the tree, so that server can allocate the array.

- prakash1529 April 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You are describing a heap. binary tree is not necessarily a heap.
But, you can make it a heap by stubbing the NULL leaves, and then you can serialize it out the way you described.
To deserialize, I think it's easier to just reconstruct the tree then using an array.

- Anonymous April 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

A binary tree is not necessarily a heap, but a heap is necessarily some sort of tree, usually (but not always, see Fibonacci heap) binary.

- Anonymous April 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

d

- Anonymous January 22, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

c

- c January 22, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

As mentioned any two traversal can be sent for syncing details between client and server.

- Varun April 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

both traversal are required to construct the tree on the server side. Inorder is a must , u can choose between preorder or postorder.

- Anonymous April 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would send to the server in the in-order format {{1, 2, {3, 4, null}}, 5, {7, {null, 8, 6}, 9}}, there will be 3 elements in the curly brace representing left, root and right, you can as well put them as left, root, right for easier construction of tree on the server. On the server we would construct a tree using the java class, so that it will be easier for other operations on the tree.

- Naveen Reddy Mandadi January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In case the data is complex we would need to escape braces "{", "}" and comma "," in the text and un-escape at the server.

- Naveen Reddy Mandadi January 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

List<Character> serialization(Node root) {
List<Character> list=new ArrayList<Character>();
if(root==null) {
list.add('#');
} else {
list.add(root.val);
list.addAll(serialization(root.left));
list.addAll(serialization(root.right));
}
return list;
}

Node deSerialization(List<Character> list) {
char c=list.get(0);
list.remove(0);
if(c=='#') return null;
Node root=new Node(c);
root.left=deSerialization(list);
root.right=deSerialization(list);
return root;
}

- Anonymous October 26, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More