Microsoft Interview Question for Software Engineer in Tests






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

see www,,careercup,,com__question?id=388843

- Anonymous February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

uh i am stuck in an infinite loop.

- Anonymous February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse_list()
{
struct list *temp;
temp=head;
if(head!=NULL & head->next!=NULL)
{
head=head->next;
reverse_list();

temp->next->next=temp;
temp->next=NULL


}
display()
}
----------------------Iterative solution----------------------
void reverse()
{
struct list *temp, *temp1;
if(head==NULL)
pf("no nodes");
temp=head->next; //temp is the new head->next
head->next=NULL //head ka next is now null
temp1=temp->next;//temp storage to move to head -> next ->next
temp->next=head; //restore new temp to point to head
head=temp; //temp is the new head
temp=temp1; //temp1 is the new temp

display();
}

- kunal karoth February 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Node Reverse(Node n)
{
	if(n.next != null)
	{
		Node t = Reverse(n.next);
		AddAtEnd(t, n);
		return t;
	}
	else return n;
}

void AddAtEnd(Node t, Node n)
{
	Node k = t;
	while(k.next != null) k = k.next;
	k.next = n;
}

- Anonymous March 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This goes into a infinite loop!!!

in the AddAtEnd function the second line takes it to infinite loop!!!

- rvired March 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <malloc.h>
typedef struct list{
    struct list *next;
    int val;
}list;

list *root=NULL;

void alloc(list **node, int val)
{
    *node = (list *)malloc(sizeof(list));
    (*node)->next=NULL;
    (*node)->val = val;
}
void BuildLinkedList()
{
    int i;
    int len=0;
    list *end, *temp;
    printf("Enter the number of elements:");
    scanf(" %d",&len);
    for(i=0;i<len; i++)
    {
        if(root == NULL)
        {
            alloc(&root,i+1);
            end = root;
            continue;
        }
        else
            alloc(&temp, i+1);
        end->next = temp;
        end = temp;

    }
}
void PrintList(void)
{
    list *temp = root;
    while(temp != NULL)
    {
        printf(" %d", temp->val);
        temp = temp->next;
    }
    printf("\n");
}

list * ReverseLinkedList(list *temp)
{
    list *t;
    if(temp == NULL)
    {
        printf("Empty Linked List\n");
        return NULL;
    }
    if(temp->next != NULL)
        t = ReverseLinkedList(temp->next);
    else return temp;
    temp->next->next = temp;
    if(temp == root)
        temp->next = NULL;
    return t;
}
int main(void)
{
    BuildLinkedList();
    PrintList();
    root = ReverseLinkedList(root);
    PrintList();
}

- Anonymous March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursive Option:

//pass argument such as (linkList, NULL) in the beginning.
Node* ReverseLinkList( Node *list, Node *mergeList)
{
Node* nextNode = NULL;
nextNode = list->next;

//list should never reach NULL, so don't worry about this.
list->next = mergeList;

if(nextNode != NULL) return ReverseLinkList1(nextNode, list);
else return list;
}

- DM April 18, 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