152. Find Top k Elements

JavaScriptAlgorithm
Is this helpful ?

medium  - accepted / - tried

Given an unsorted array of integers which might have duplicates, return the top k integers in non-ascending order.

topK([1,10,8,9,10,2,3,4,8,8,6], 4)
// [10, 10, 9, 8]

What is the time & space cost of your code ? Could you do better ?

Let's try to solve this problem within 10 mintues.

Discuss(22)