Pregunta de entrevista de Yahoo

Find the kth largest element in an array

Respuestas de entrevistas

Anónimo

21 de mar de 2017

Why not use a PriorityQueue and solve?

1

Anónimo

24 de feb de 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.

Anónimo

24 de feb de 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.