Question d’entretien chez Yahoo

Find the kth largest element in an array

Réponses aux questions d'entretien

Utilisateur anonyme

21 mars 2017

Why not use a PriorityQueue and solve?

1

Utilisateur anonyme

24 févr. 2017

Initiate an list of k elements maximum length . Move through the array, tracking a max index of the queue and min index . While iterating, add the array item if the list has less than k items. If it does have more than k items, swap the smallest value in the list out with the max value, and realign the max and min value pointers. When the array is fully iterated through, sort the list and find the kth largest value.

Utilisateur anonyme

24 févr. 2017

Initiate an list of k elements maximum length . Move through the array, tracking a max index of the queue and min index . While iterating, add the array item if the list has less than k items. If it does have more than k items, swap the smallest value in the list out with the max value, and realign the max and min value pointers. When the array is fully iterated through, sort the list and find the kth largest value.