Microsoft Interview Question for Software Engineer in Tests






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

How about this?

TraverseList (Node head)

{

Node n1, n2;
n1 = head;

if (n1 == null) return;

n2 = n1;
Print n2.value;
while (n2.next != null && n2.next != n1)
{
n2 = n2.next;
print n2.value;
}

}

- raj November 07, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

raj that code doesn't work very well, first it only detects cycles that include the head node, plus it is really inefficient in the number of checks. something like this is better but doesn't have any cycle checks as I don't want to put it in. But go for it, here is a framework.

int traverse_list(node* n)
{

while(n) {

printf("%d", n->value);
n = n->next;

}

return 0;

}

- Anonymous November 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Anonymous,

the solution provided by u is good for singly linked list, and doubly. but how abt circular.

my solution will work for all...

- raj November 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

test cases would be
empty list
1 element in list
circular list
many elements in list

- Anonymous November 12, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Raj,

You are the biggest moron I have seen .Your check for finding cycle is wrong. Can this find the cycle with 1 2 3 1 . No it can't because each time first node will be one behind the second node owing to which it will keep revolving inside the loop without detecting. Get your concepts clear and then posts the solutions.

- doubt July 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I understand there should be test case for deletion. But not sure how to make test case for that. How can I make sure that if I invoke to delete a node, there is no memory leak.

- neo September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use valgrind to detect memory leaks

- memory leak October 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 0 vote

Assumptions
1. Singly Linked List.
2. Do not print complete list in case of Loop.

Scenarios
1. Empty List
2. Loop in the List.
3. n>0, elements in the list.
4. Memory corrupted node.

void TraverseList(NODE head)
{
NODE ptr1,ptr2;
ptr1= head;
if(NULL == ptr1) return;
ptr2 = head->next;
while(ptr1!=ptr2)
{
ptr1=ptr1->next;
if(ptr2) ptr2=ptr2->next;
if(ptr2) ptr2=ptr2->next;
Print ptr1;
}
if(ptr1)
Print Loop found
}

Please add memory corrupt detection code in it.

- Ankush Bindlish November 05, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is this memory corrupt?how will you test this case?

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

what is memory corrupt case?how will you detect that?

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

what is memory corrupt case?how will you detect that?

- vishwaatma July 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is this memory corrupt?how will you test this case?

- vishwaatma July 03, 2010 | 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