Motorola Interview Question for Software Engineer / Developers






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

What si understand is id tree is follow:

1
   2     3
 4   5 6   7

then output is: 1 2 3 7 6 5 4.

Is this teh expection ?

- SRB April 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes .. exactly ..

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

Srry i only replied anonymously ..

thats what the interviewer expected

- karthik.sriharsha April 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use two queues

or use one queue and a flag variable

- camSun April 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can we do something like this:
1. stack the root
2. Pop from stack and add its children to queue
3. Delete from queue and add their children to stack
4. Repeat from 2 above

- Sireesha April 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

just to describe Sireesha answer -> traverse in BFS manner

- Anonymous June 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
private static void alternateLevelOrder(ArrayList<Integer> list, Node root) {
LinkedList<Node> queue = new LinkedList<Node>();
LinkedList<Node> queue2 = new LinkedList<Node>();
boolean reverse = true;
queue2.add(root);
while ((queue.size() + queue2.size()) > 0) {
if (queue.size() > 0) {
Node start = queue.poll();
if (start.left != null) {
// list.add(start.left.data);
queue2.add(start.left);
}
if (start.right != null) {
// list.add(start.right.data);
queue2.add(start.right);
}
} else {
queue.addAll(queue2);
if (reverse) {
Collections.reverse(queue2);
} else {
}
for (Node node : queue2) {
list.add(node.data);
}
queue2.clear();
reverse = !reverse;
}
}
}
}

- gurusamy June 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you are right

- anonymous March 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

OK :)

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

BFS using 2 stacks..

- anony July 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

level order traversal...

- addi November 02, 2011 | Flag


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