Frage im Vorstellungsgespräch bei Google

Find the kth largest element in a sorted array.

Antworten zu Vorstellungsgespräch

Anonym

23. Mai 2015

The described the algorithm and also wrote some code.

Anonym

7. März 2016

Your solution wouldn't work if the array as duplicate. {1,2,3,3,4,5,5,6} k = 2 result should be 5

Anonym

31. Mai 2015

If the array is already sorted, can't you just return n-k element? public static int kthLargest(int [] array), int k { if (array.length == 0 || k > array.length) { throw new llegalArgumentException(); } return array[ array.length - k]; }