Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Solution: Top 'K' Numbers

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 2 years ago

from heapq import * class Solution:   def findKLargestNumbers(self, nums, k):     # O(n)     heap = [-n for n in nums]     heapify(heap)     # O(k log n)     return [       -heappop(heap) for _ in range(k)     ]
A

Anonymous

· 3 years ago

I am able to use Priority Queues in C# with no problem on Leetcode but when I try to use it here it is missing an assembly reference.

A

Anonymous

· 3 years ago

In the solution to this problem, there are images that visually demonstrate the algorithm on an example. But the last 3 images in this sequence are duplicates.

A

Anonymous

· 3 years ago

Can't Find different approach as mentioned in Note.

"Note: For a detailed discussion about different approaches to solve this problem, take a look at Kth Smallest Number."

Both ("Top 'K' Numbers" and "Kth Smallest Number") problem solved with same strategy.

Reading Progress

0%


Vote for new content