Microsoft Interview Question for Software Engineer in Tests






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

main() {
     reverse(head, null, newHead);
}

public void reverse(Node head, Node prev, Node newHead) {
      Node next;
      if (head.getNext() != nulll) {
                next = head.getNext();
      }
      head.setNext(prev);
      prev = head;
      if (next != null) {
             reverse (next, prev)
      }
      else {
             newHead = head;
      }
}

- anonymous June 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
if you are talking about the a linklist such as the one inplemented by Java then i guess you could just swap the the contents of each node {{{ {{{ import java.util.LinkedList; class crrcup{ public void reverse(LinkedList<Integer> list, int index1, int index2){ Integer temp=null; if((index1!=index2)&&(index1<index2)){ temp=list.get(index1); list.add(index1, list.get(index2)); list.remove(index1+1); list.add(index2, temp); list.remove(index2+1); reverse(list, index1+1,index2-1); } } public static void main (String args[]){ LinkedList<Integer> list = new LinkedList<Integer>(); crrcup m= new crrcup(); for(int i=0;i<20;i++)list.add(i); m.reverse(list, 0, list.size()-1); for(int i=0;i<list.size();i++)System.out.print(list.get(i)+" "); } } }}} - Kes August 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Node reverse(Node head,Node previous){
    if(head == null)
	    return previous;
	 Node tmp = head.next;
	 head.next = previous;
	 prevoous = head;
	 
	 reverse(tmp,previous);


}

- akshay.shetye August 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

node *reverse(node *head) {
   if(head == NULL || head->next == NULL)
      return head;
   node *p = head->next;
   node *q = reverse(p);
   p->next = head;
   head->next = NULL;
   return q;
}

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

<pre lang="" line="1" title="CodeMonkey77235" class="run-this">struct node
{
int data;
struct node *next;
};

void Reverse(struct node **headRef)
{
struct node *first;
struct node *rest;

if(NULL == *headRef) return;

first = headRef;
rest = first->next;

if(NULL == rest) return;

Reverse(&rest);

first->next->next = first;
first->next = NULL;

*headRef = rest;
}</pre><pre title="CodeMonkey77235" input="yes">
</pre>

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

if (head == null) {
			return;
		}
		reverseByRecursion(head, null);
	}
	
	public void reverseByRecursion(ListNode node, ListNode prev) {
		ListNode temp = node.getNext();
		node.setNext(prev);
		if (temp == null) {
			head = node;
			return;
		}
		reverseByRecursion(temp, node);
	}

- anonymous February 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

// formatting it properly

if (head == null) {
return;
}
reverseByRecursion(head, null);


public void reverseByRecursion(ListNode node, ListNode prev) {
ListNode temp = node.getNext();
node.setNext(prev);
if (temp == null) {
head = node;
return;
}
reverseByRecursion(temp, node);
}

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

// formatting it now

if (head == null) {
	return;
}
reverseByRecursion(head, null);
	
public void reverseByRecursion(ListNode node, ListNode prev) {
		ListNode temp = node.getNext();
		node.setNext(prev);
		if (temp == null) {
			head = node;
			return;
		}
		reverseByRecursion(temp, node);
}

- anonymous February 18, 2012 | 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