Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Mohammed Dh Abbas
Max Heap is the wrong!! it should be Min heap

Mohammed Dh Abbas

May 9, 2024

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

0

0

Comments
Comments
L
lejafilip a year ago

max heap is also valid.

On this page