Microsoft Interview Question for Software Engineer in Tests






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

while(node->next)
{
if(node->data<=val && node->next->data >=val)
{
new->next=node->next;
node->next=new;
}
else
{
node=node->next;
}
}

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

This solution wont work if the element to be inserted is the first element i.e if we have 2 3 4 5 and we try to insert 1.
Same goes with the last element also.
You need to check these conditions too.

- CodeNotguru April 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to check these cases:
Case 1. An inserted node is the first one to be added to an empty list.
Case 2. The inserted node’s key is less than those of all others in the list; thus, the node goes at the beginning of a nonempty list.
Case 3. The key is greater than all the others; thus, the node goes at the end of the list.
Case 4. The key lies between two others; thus, the node goes in the middle of the list somewhere.

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

you are probably asked to write the O(n*log) solution, this is O(n).

A simple solution would be using merge sort...
Scan through the list and count n. Then you divide by considering first n/2 and last n/2. Then "break" the list into parts, sort them recursively and "join" the two lists.

- pratik April 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

first of all, why sorting? it is already sorted.

second, linked list doesn't have random access, it is inefficient to do binary search.

third, O(n*log) > O(n)

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

void insert(Node **header, int value)
{
    if(**header && *header)
    {
        if((*header)->value>value)
        {
            Node *newHeader=new Node();
            newHeader->value=value;
            newHeader->next=*header;
            *header=newHeader;
        }
        else
        {
            Node *current=*header;
            
            while(current->next && current->next<=value)
            {
                current=current->next;
            }
            
            Node *newNode = new Node();
            newNode->value = value;
            newNode ->next = current->next;
            current->next =newNode;
        }
    }
    
    else if(**header && *header == NULL)
    {
        *header=new Node();
        *header->value=value;
    }
}

- Anonymous March 01, 2011 | 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