Microsoft Interview Question for Software Engineer in Tests






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

void reverseAlternateNodes(struct node **head)
{
struct node *p1 = *head;
struct node *prev = NULL, *temp;
if(p1 == NULL || p1->link == NULL)
return;
else
{
*head = p1->link;
while(p1 != NULL && p1->link != NULL)
{
if(prev != NULL)
prev->link = p1->link;
temp = p1->link->link;
p1->link->link = p1;
p1->link = temp;
prev = p1;
p1 = p1->link;

}
}
}

- HelpThyDeveloper September 06, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if(head==null||head->next==null)return head;
ptr1= head;
ptr2=ptr1->next;
head=ptr2;
while(ptr2!=null){
ptr3=ptr2;
ptr2=ptr1->next;
ptr1->next=ptr2->next;
ptr2->next=ptr1;
if(head!=ptr3)ptr3->next=ptr2;
ptr2=ptr1;
ptr1=ptr1->next;
}

- bindas September 01, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

node* func(node* head)
{
if(!head||!head->next)
return head;
node* curr=head;
node* temp;
head=curr->next;
while(curr->next)
{
temp=curr->next;
curr->next=curr->next->next;
temp->next=curr;
curr=curr->next;
}
return head;
}

- winia September 02, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Doesnt Work! check!

- Devil007 February 12, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is correct one.

node* func(node* head)
{
if(!head||!head->next)
return head;
node* curr=head;
node* temp;
head=curr->next;
while(curr&&curr->next)
{
temp=curr->next;
curr->next=curr->next->next;
temp->next=curr;
curr=curr->next;
}
return head;
}

- winia September 02, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not correct ,
e.g, list a->b->c->d->e->f->g

//curr = a, curr->next = b
while(curr&&curr->next)
{
temp=curr->next; // temp = b
curr->next=curr->next->next; // a -> c
temp->next=curr; // b -> a
curr=curr->next; // cur = c
}
so after the first loop
b-> a -> c -> d -> e -> f
after the second loop
b-> a -> c
d-> c -> e -> f not correct!!!

- redroof November 17, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//memcpy considering overlap
void* memcpy(void* dst,void* src,int count)
{
//no overlappoing or overlapping happens at the lower address of the source
if(((char*)dst>(char*)src+count)&&(dst<src))
{
while(count)
{
*(char*)dst=*(char*)src;
dst=(char*)dst+1;
src=(char*)src+1;
count--;

}
}
else
{
//there is overlap at the higher address of the source, then start copying from the higher address
dst=(char*)dst+count-1;
src=(char*)src+count-1;
while(count)
{
*(char*)dst=*(char*)src;
dst=(char*)dst+1;
src=(char*)src+1;
count--;

}
}
}

- Jackie September 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

correcting the condition :-
if(((char*)dst>(char*)src+count)||(dst<src))

- nkb September 06, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry a typo:
//memcpy considering overlap
void* memcpy(void* dst,void* src,int count)
{
//no overlappoing or overlapping happens at the lower address of the source
if(((char*)dst>(char*)src+count)&&(dst<src))
{
while(count)
{
*(char*)dst=*(char*)src;
dst=(char*)dst+1;
src=(char*)src+1;
count--;

}
}
else
{
//there is overlap at the higher address of the source, then start copying from the higher address
dst=(char*)dst+count-1;
src=(char*)src+count-1;
while(count)
{
*(char*)dst=*(char*)src;
dst=(char*)dst-1;
src=(char*)src-1;
count--;

}
}
}

- jackie September 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Works perfectly - check it

Node* swapNodes(){
		Node* cnode = head;
		Node* tempnode1;
		Node* tempnode2;
		if(cnode && cnode->next){
			tempnode1 = cnode;
			cnode = cnode->next;
			head = cnode;
			tempnode2 = cnode->next;
			cnode->next = tempnode1;
			cnode->next->next = tempnode2;
			cnode = cnode->next;
		}
			
		while(cnode->next && cnode->next->next){
			tempnode1 = cnode->next;
			cnode->next = cnode->next->next;
			tempnode2 = cnode->next->next;
			cnode->next->next = tempnode1;
			cnode->next->next->next = tempnode2;
			cnode = cnode->next->next;
		}
		return head;
		
	}

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

recursion can simplify the implementation

List * swap_pair_list(List *head)
{
	if(head == NULL || head->next == NULL)
		return head;
	
	List *p1 = head;
	List *p2 = head->next;
	List *next = head->next->next;
	

	p2->next = p1;
	head = p2;
	p1->next = swap_pair_list(next);

	return head;
}

- summer February 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

summer's solution is good

- ckk October 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void swap_pair(lnode **head)
{
if(!*head)
return;

lnode* prev = 0;
lnode* fst = *head;
lnode* scd = fst->nxt;

if(!scd)
	return;
*head = scd;

while(1)
{

fst->nxt = scd->nxt;
scd->nxt = fst;

if(prev)
	prev->nxt = scd;

if(!fst->nxt || !fst->nxt->nxt)
	break;

prev = fst;
fst = fst->nxt;
scd = fst->nxt;

}
}

- i.shahin September 25, 2010 | 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