Ebay Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Does the new list has to be sorted as well ? Can u give an example ?

- An Enthusiast April 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes the output list also should be sorted.

- Vin April 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

first n elements sorted, so increment ptr n/2 places and sort the next n elements. Then do the same thing until whole list sorted. (m/n) * nlogn = mlogn runtime assuming m = total num elements across all lists.

- DPak April 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Lets say each list is of size M
Take list[0],list[1] merge them, take list[2],list[3] merge them,.. take list[n-2],list[n-1] and merge them
Next take two previously sorted list and merge them, keep doing this unil there is one list remaining.
compleixty O(MXN)

or

Merge the list[0] and list[1] call the merged list mergeList
for(i = 2 ; i < n ;i++)
merge(mergeList, list[i])
This is again a O(MXN) algo

- Wolverine April 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is not O(M X N) it is i guess O(M X N X log(N))

- Praveen September 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct node{
	node * next;
	int data;

};

node * simple_merge(node * list1, node * list2)
{	
	node * result = NULL;
	node * p1 = list1;
	node * p2 = list2;
	node * p3 = NULL;
	while(p1!=NULL && p2!=NULL)
	{
		node * chosen = NULL;
		if(p2== NULL|| (p1!=NULL && p2->data > p1->data))
		{
			chosen = p1;
			p1 = p1->next;
		}
		else
		{
			chosen = p2;
			p2 = p2->next;
		}
		
		if(result == NULL)
		{
			result = chosen;
			p3 = result;
		}
		else
		{
			p3->next = chosen;
			p3 = chosen;
		}
		chosen->next = NULL;
		
		
		
	}
	return result;
}

node * merge_lists(node ** lists, int numLists)
{
	node * result = NULL;
	node ** currents = new node * [numLists];
	if(numLists == 1)
	{
		result = lists[0];
	}
	if(numLists == 2)
	{
		result=simple_merge(lists[0], lists[1]);
	}
	else
	{
		int index = numLists/2;
		node * result1= merge_lists(lists, index);
		node * result2 = merge_lists(lists[index+1], numLists-index);
		result=simple_merge(result1, result2);
	}
	return result;

}

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

public static Node NmergeSort(LinkedList A[]){
int N= A.length;
Node res=null;
Node node = new Node(null, 0);
while(A.length>0){
int min = Integer.MAX_VALUE;
int I=-1;
for(int i=0;i<N;i++){
if(A[i]!=null && A[i].head.val<min){
min = A[i].head.val;
I=i;
}
}
node = A[I].head;
A[I].head = A[I].head.next;
if(res==null){
res = node;
}else{
node.next=res;
res=node;
}
}
return res;
}

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

public static Node NmergeSort(LinkedList A[]){
int N= A.length;
Node res=null;
Node node = new Node(null, 0);
while(A.length>0){
int min = Integer.MAX_VALUE;
int I=-1;
for(int i=0;i<N;i++){
if(A[i]!=null && A[i].head.val<min){
min = A[i].head.val;
I=i;
}
}
node = A[I].head;
A[I].head = A[I].head.next;
if(res==null){
res = node;
}else{
node.next=res;
res=node;
}
}
return res;
}

- rathor.rajeev September 01, 2016 | 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