Question d’entretien chez Google

Find the kth largest element in a sorted array.

Réponses aux questions d'entretien

Utilisateur anonyme

23 mai 2015

The described the algorithm and also wrote some code.

Utilisateur anonyme

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

Utilisateur anonyme

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