Sort 232 Discussions, By:
Please Login in order to post a comment
This problem is mistakenly placed into Queue subdomain, while it must be placed under 'Heap'.
I wasted some time trying to understand how it's possible to effectively use a queue (and not min-heap that immediately comes to mind).
This crummy trend in Hackerrank problem description is becoming really annoying. Please provide more test cases and/or explain better the problem.
Here the "-1" case is really ambiquious and I had to take shots on what the author had in mind...
Getting testcase 18 as wrong . Can't figure out what edge case I'm missing
solution for python 3 using heapq
from heapq import heappop,heappush,heapify
firstLine = [int(x) for x in input().split()]
cookies = [int(x) for x in input().split()]
cookieCount = int(firstLine)
minSweetness = int(firstLine)
fC = 0
while cookies < minSweetness:
c1 = heappop(cookies)
c2 = heappop(cookies)
Even though I'm heapifying the array only once and using min-heap to store and operate on the data, I'm getting timeouts from cases #20, #21, #22 and #23. (large inputs)
My submission is here: https://www.hackerrank.com/challenges/jesse-and-cookies/submissions/code/28210608 any ideas how I can make this faster? I could not spot any issues with my heap, my pop/push operations are O(logn).