Real Networks Interview Question for Software Engineer / Developers






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

perform counting sort and create an integer array of length 50.
that would surely do the job..

- saumils1987 August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why sort the numbers first? Is it more efficient?

- lupuslupus August 31, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorting by any means other tha counting sort cannot be less than O(nlogn)..
whereas counting sort give it in O(n) at the cost of space.\
this sorting technique is applicable when we know the range of data.
i hope i have explained it well now.

- saumils1987 August 31, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

public static void printOccurs(int [] array){
int [] record=new int [51];

for (int i=0;i<array.length;++i){
record [array[i]]++;
}

for (int i=0;i<array.length;++i){
System.out.println(array[i]+ " occurs" + new Integer(record[array[i]])+" time(s)");
}
}

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

I am not really sure why sorting is necessary at all since all we have to do is find out the frequency of each number in the array.

I would go for hashing the array where the key=number and value=frequency of number.
Hashing and printing the values would take n+n time=O(n) time and also due to the hash table O(n) space complexity

- TikTok August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hash table seems a bit overkill when the range is only 1-50. An array of size 50 does the job fine.

- lupuslupus September 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

counting sort is not really "sort". it is like bucket sort. put every item into propertied bucket. in this case, increment the item whose index is indicated by value of the item.
int[] arr = int[50];
for(int i:arrlist){
arr[i]++;
}

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

counting sort is not really "sort". it is like bucket sort. put every item into propertied bucket. in this case, increment the item whose index is indicated by value of the item.
int[] arr = int[50];
for(int i:arrlist){
arr[i]++;
}

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

What saumil suggests is using the counts from the counting sort stage. since the range 1-50 is known we can store in a array the counts.

Hash approach sugested by someone else is exactly the same but it is typically better to use an array if the range is known. Think of a Array as the Perfect hash.

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

What saumil suggests is using the counts from the counting sort stage. since the range 1-50 is known we can store in a array the counts.

Hash approach sugested by someone else is exactly the same but it is typically better to use an array if the range is known. Think of a Array as the Perfect hash.

- AD September 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How abt this approach??

for(int i = 0 ; i < n ; i++){
a[a[i]] = a[i]+(a[a[i]]%a[i]);
}

for(int i = 0 ; i < 50 ; i++){
cout << "no of occurances of" << i << ": ";
int occur = a[i]/i;
if(a[i]%i == 0)
occur--;
cout << occur << endl;
}

correct if this is inefficient

- San September 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think you can't modify Original Array (because if you do this then, how to count freq. of modified values )...we need to have another array...and this leads us o(n) extra space...

- Anonymous September 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think you can't modify Original Array (because if you do this then, how to count freq. of modified values )...we need to have another array...and this leads us o(n) extra space...

- nagpal_dce September 04, 2010 | 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