Loading...
Engaged Employer
Why Yelp? Tell me about a project you worked on lately. Given an array, return the smallest k elements from the array.
Anonymous
in python: sorted(array)[0:k]
Sorting is O(nlogn). Better time complexity, store in priority queue then return an array of the last k elements. Time complexity: O(n).
^ That is not O(n). It is O(n + klogn) and you can do better than that.
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalized job recommendations and updates by starting your searches.