Domanda di colloquio di Amazon

Leetcode easy: Return k largest number.

Risposte di colloquio

Anonimo

25 nov 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

Anonimo

25 gen 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