We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Heap
- Jesse and Cookies
- Discussions
Jesse and Cookies
Jesse and Cookies
Sort by
recency
|
358 Discussions
|
Please Login in order to post a comment
Here is my solution. It uses python heapq library. It is fast
do you knwo what is the difference between your code and: for some reason having if A[0] >= k: inside while loop makes case 18 fail def cookies(k, A): # Write your code here heapq.heapify(A) count = 0 while len(A) >= 2: if A[0] >= k: return count x = heapq.heappop(A) y = heapq.heappop(A) heapq.heappush(A, x+(2*y)) count += 1 return -1
JAVA Using PriorityQueue
Guys, I implemented the whole MinHeap and stuff:
However, test case 22 was throwing a TLE, so I cahnged the whole code for this instead: