I recently attended an interview where I was asked \"write a program to find 100 largest numbers out of an array of 1 billion numbers.\"
I was only able to give a br
Problem: Find m largest elements of n items where n >>> m
The simplest solution, that should be obvious to everyone is to simply do m passes of the bubble sort algorithm.
then print out the last n elements of the array.
This requires no external data structures, and uses an algorithm that everyone knows.
Running time estimate is O(m*n). The best answers so far is O(n log(m)), so this solution is not significantly more expensive for small m.
I'm not saying this couldn't be improved, but this is by far the simplest solution.