You are viewing a single comment's thread. Return to all comments →
C# Solution!
public static int cookies(int k, List<int> A) { int count = 0; var pqueue = new PriorityQueue<int,int>(); foreach(int e in A) pqueue.Enqueue(e,e); while(pqueue.Count>1) { int x = pqueue.Dequeue(); if(x>=k) { return count; } else { int y = pqueue.Dequeue(); int c = x + (2*y); pqueue.Enqueue(c,c); count++; } } if(pqueue.Peek()>=k) return count; else return -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
C# Solution!