Pergunta de entrevista da empresa Yelp

Why Yelp? Tell me about a project you worked on lately. Given an array, return the smallest k elements from the array.

Respostas da entrevista

Sigiloso

27 de jan. de 2016

in python: sorted(array)[0:k]

1

Sigiloso

23 de mai. de 2016

Sorting is O(nlogn). Better time complexity, store in priority queue then return an array of the last k elements. Time complexity: O(n).

1

Sigiloso

18 de set. de 2016

^ That is not O(n). It is O(n + klogn) and you can do better than that.