You are viewing a single comment's thread. Return to all comments →
int cookies(int k, vector<int> arr) { priority_queue<int, vector<int>, greater<int>> pq(arr.begin(), arr.end()); int count = 0; while (pq.size() > 1 && pq.top() < k) { int first = pq.top(); pq.pop(); int second = pq.top(); pq.pop(); pq.push(first + 2 * second); count++; } return (pq.top() >= k) ? count : -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →