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.

You can solve this without a heap, only use pure Queue. You need to sort the input first, and then use two simple Queue. An init queue and an other to store the new made cookies.
Every time a cookie is made, the time complexity will be constant time.
The final time complexity will be O(nlogn + number of operations).

## Jesse and Cookies

You are viewing a single comment's thread. Return to all comments →

hint : use priority_queue

priority queue is NOT a queue. It's a heap.

oh. then, use 2 queues. but, sort it before u push the inputs to the first queue.

That makes no sense sir. This question requires a min heap priority queue which in reality is not a f-i-f-o queue.

You can solve this without a heap, only use pure Queue. You need to sort the input first, and then use two simple Queue. An init queue and an other to store the new made cookies. Every time a cookie is made, the time complexity will be constant time. The final time complexity will be O(nlogn + number of operations).

a heap can be used to implement a priority que and thus they are synonymos.

A[0] remains empty A[1] is the heap head (max or min your choice) and for A[k] the left node is at A[2k] and the right at A[2k + 1]

here is my solution using a PriorityQueue

It inherits from java.util.AbstractQueue, but it is NOT queue tho

In C++ as well, they have kept it under , may be while deciding the container, they might have given preference ot application over implementation.

It could be. But it is just so confusing at the first place