Pergunta de entrevista da empresa Yahoo

Find the kth largest element in an array

Respostas da entrevista

Sigiloso

21 de mar. de 2017

Why not use a PriorityQueue and solve?

1

Sigiloso

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

Sigiloso

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