Amazon Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
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 )
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)
- mrb February 27, 2012