Ebay Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Counting sort

public static void countingSort(int [] m)
	{
		int [] counts=new int[10];
		for(int i=0;i<counts.length;i++)
			counts[i]=0;
		for(int i=0;i<m.length;i++)
		{
			counts[m[i]]++;
		}
		int counter=0;
		for(int i=0;i<counts.length;i++)
		{
			for(int j=0;j<counts[i];j++)
			{
				m[counter]=i;
				counter++;
			}
		}
	}

- Vincent August 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is having O(n2) time complexity

- Ashmit August 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dont think so.counts.length is a constant- the question states that only single digit numbers are present in the list (0-9). So that keeps the complexity at O(n).

You do not have 'n' numbers with each number having 'n' as its frequency. That would be O(n^2).
Please correct me in case I have messed up.

- Saurabh August 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great, this is even simpler than the algorithm given in CLRS!

- rajarshi129 October 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use bucket sort.

- Luke August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create BST and then inorder traversal

- BS September 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

method 1: use an array of arr[10] for ten 1digit numbers.
increment count of digit in array.
print the digit no of times specified in the array

unsorted list 6 1 4 1

arr 0 1 2 3 4 5 6 7 8 9
val 0 2 1 0 1 0 1 0 0 0

sorted list: 1 1 4 6

method 2:
use radix sort if array can fit in memory

- Drishti March 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Shouldn't second last for loop be -

for(int i=0;i<10;i++)

- Nakul March 24, 2013 | 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