- Jesse and Cookies
- Discussions

# Jesse and Cookies

# Jesse and Cookies

+ 6 comments Python3 solution using the built in heapq library:

import heapq def cookies(k, A): heapq.heapify(A) ops = 0 while True: f = heapq.heappop(A) if f >= k: return ops if len(A) == 0: return -1 s = heapq.heappop(A) n = f + 2*s heapq.heappush(A, n) ops += 1

+ 3 comments 3 days and about 10 attempts (include selfmade binary search for insert value to sorted array). I love it:). I solved this problem using two queues:

In the first queues copy sorted list. In the second queue will write all calculated values (1cookie +2x 2cookie). This queue is automaticaly sorted because values increase . When extracting the value, select the minimum between two queues.

Sorry of bad English, i'm just learning)

+ 1 comment in the first example they remove the cookie with sweetness '7' twice, once with 6 and once with 8. is this an error or am I misunderstanding the whole remove the cookies part?

+ 1 comment Something is up with the performance limits on this one. The number of test cases failing due to timeout ranges from 1 to 3 (literally running the exact same code). One test case in particular I ran in Groovy console and it took less than 0.5 seconds to get the correct answer, which seems like it should be well below the time limit.

+ 1 comment Relatively straightforward with the C++ standard library. I used multiset as the primary data structure.

Sort 57 Discussions, By:

Please Login in order to post a comment