Skip to content

Commit

Permalink
Create 3066. Minimum Operations to Exceed Threshold Value II (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Feb 13, 2025
2 parents 285520a + 5800a0f commit d4478d7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 3066. Minimum Operations to Exceed Threshold Value II
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
int minOperations(vector<int>& nums, int k) {
priority_queue<long long, vector<long long>, greater<long long>> pq;
for (auto& num : nums) {
pq.push(num);
}

int minOp = 0;
while (pq.size() >= 2 && pq.top() < k) {
long long x = pq.top();
pq.pop();
long long y = pq.top();
pq.pop();
long long z = x * 2 + y;
pq.push(z);
minOp++;
}

return minOp;
}
};

0 comments on commit d4478d7

Please sign in to comment.