Domanda di colloquio di Google

Find the kth largest element in a sorted array.

Risposte di colloquio

Anonimo

23 mag 2015

The described the algorithm and also wrote some code.

Anonimo

7 mar 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

Anonimo

31 mag 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]; }