Pergunta de entrevista da empresa Amazon

Leetcode easy: Return k largest number.

Respostas da entrevista

Sigiloso

25 de nov. de 2020

- put all elements in Set data structure - pop all first K-1 elements - return the top element --> [N logN run time and N extra space] ========== - sort the array - return the Kth element

Sigiloso

25 de jan. de 2021

Create a max heap using the given array/list elements. for(i = 0 to k-1 times){ swap first element with last element; heapify the array for indices 0 to arrSize-i; } return arr[0]; Space Complexity: O(1) Time Complexity: (k-1)logn where n is number of elements