I am having some problems with a sorting problem.
The statement:
Write a method KthLargest()
that, given an array containing integers in some arbitrary order and an integer k, returns the k-th largest element in the array. Assuming that k is a small number and n is a very large number, your algorithm should be as fast as possible in terms of the worst-case number of comparisons, so do not sort the entire array of size n to find out the k-th largest element. You may use the Arrays.sort() method provided in the Java library.
I have clear ideas on how to do this problem... That is if I can sort the entire array first.
public static int KthLargest(int[] inputArray, int k)
{
Arrays.sort(inputArray);
return inputArray[k];
}
However, the problem statement specifically states that I must not sort the entire array.