Amazon Interview Question for Software Engineer / Developers






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

private static LinkedList merge(Node a, Node b) {
		// TODO Auto-generated method stub
		LinkedList merge = new LinkedList();
		Node dummy=new Node();
		Node tail = dummy;
		while(a!=null && b!=null){
			if(a.data<b.data){
				tail.next = a;
				a= a.next;
				tail = tail.next;
			}
			else{
				tail.next = b;
				b=b.next;
				tail = tail.next;
			}
		}
		if(a==null){
			tail.next = b;
		}
		if(b==null){
			tail.next =a;
		}
		merge.root = dummy.next;
		return merge;
	}

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

How about this

//Make sure list1.data < list2.data
public Node mergeLinkedList(Node list1, Node list2){

	if(list1 == null) return list2;
	if(list2 == null) return list1;

	while(list1.next != null && list2.next !=null){
		if(list1.data <= list2.data) list1 = list1.next;
	}

	list1.next = mergeLinkedList(list2, list1);
	return list1;
}

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

NA

- weijiang2009 February 06, 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