Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

don't sort, if the order of selected 50 students is preserved, then binary search in O(log N) time.
else, every other student must be compared. ==> O(N) time, (below code)

b = selected_boy;
count = 0;
for each student s: selected_list{
	if( s.rank < boy.rank)
		count++;
}
return count+1;

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

If order is not preserved can we use a selection algorithm to decide its rank by using the partition step of quick sort?

- hello world February 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

don't sort, if the order of selected 50 students is preserved, then binary search in O(log N) time.
else, every other student must be compared. ==> O(N) time, (below code)

b = selected_boy;
count = 0;
for each student s: selected_list{
	if( s.rank < boy.rank)
		count++;
}
return count+1;

- mrb February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use the Partition Algorithm of QuickSort.- O(n)

- pradeepBansal February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use the Partition function of QuickSort.- O(n)

- pradeepBansal February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use the Partition function of QuickSort.- O(n)
Use the element whose rank is to be evaluated as the pivot.

- pradeepBansal February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Perspective - 1
Sort all those fifty Students/Ranks then the index of the student picked would tell you his relative position.

Perspective - 2
I am not sure, but is the question based on " Counting Sort " where you have a fixed range ( in this case 50 ) for a huge numbers of items to sort with ( in this case 100 students )

- Vijay Rajanna February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

MBR: Students are picked randomly. So don't expect input in order..
Sringeri: Sorting is a costly operation which requires nlog(n)


Need to do something different here..

- Bharath February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

MBR: Students are picked randomly. So don't expect input in order..
Sringeri: Sorting is a costly operation which requires nlog(n)


Need to do something different here..

- Bharath February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

wat if i compare the rank of the 40th rank student to all other 49 students...will that giv an optimised sol???

- raktimsaha.080 February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. The ranks of the students randomly selected will lie between 1-100. So use radix sort to sort the entries. This will take O(n) time.
2. So now the index of the element is the answer to our problem.

- Rave February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a bit array of size 100, for each of 50 students selected, set the bit of a particular student as soon as he is selected.
Now for a student's rank which is say i in 100 students, start from index 0 and move toward i, counting number of set bits, this will tell us the rank in 50.

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

shove all students into an array, unsorted - O(n) - and then count the number of students above or below the student you're looking for - O(n).

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

O(n).
Just go through all 50 students and increment a counter for every student that has a better ranking than 40.

- Guruprsad GV March 10, 2012 | 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