Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Kth Smallest Number (easy)
.....
.....
.....
Like the course? Get enrolled and start learning!
A
Anonymous
· 2 years ago
Max Heap is the wrong approach "we are asking the smallest". my solution
def findKthSmallestNumber(self, nums, k): min_heap = [] for item in nums: heappush(min_heap, item) for i in range(k): out = heappop(min_heap) if i == k - 1: return out
Show 1 reply
A
Anonymous
· 4 years ago
For the python solution in Kth Smallest Number, why is it that we are negating the values as we push them to the maxHeap?

Show 2 replies
Reading Progress
0%