Skip to content

Commit ee448af

Browse files
committedFeb 13, 2025
Add solution #3066
1 parent 7212530 commit ee448af

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@
588588
2727|[Is Object Empty](./2727-is-object-empty.js)|Easy|
589589
2948|[Make Lexicographically Smallest Array by Swapping Elements](./2948-make-lexicographically-smallest-array-by-swapping-elements.js)|Medium|
590590
3042|[Count Prefix and Suffix Pairs I](./3042-count-prefix-and-suffix-pairs-i.js)|Easy|
591+
3066|[Minimum Operations to Exceed Threshold Value II](./3066-minimum-operations-to-exceed-threshold-value-ii.js)|Medium|
591592
3105|[Longest Strictly Increasing or Strictly Decreasing Subarray](./3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js)|Easy|
592593
3110|[Score of a String](./3110-score-of-a-string.js)|Easy|
593594
3151|[Special Array I](./3151-special-array-i.js)|Easy|
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* 3066. Minimum Operations to Exceed Threshold Value II
3+
* https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii/
4+
* Difficulty: Medium
5+
*
6+
* You are given a 0-indexed integer array nums, and an integer k.
7+
*
8+
* You are allowed to perform some operations on nums, where in a single operation, you can:
9+
* - Select the two smallest integers x and y from nums.
10+
* - Remove x and y from nums.
11+
* - Insert (min(x, y) * 2 + max(x, y)) at any position in the array.
12+
*
13+
* Note that you can only apply the described operation if nums contains at least two elements.
14+
*
15+
* Return the minimum number of operations needed so that all elements of the array are greater
16+
* than or equal to k.
17+
*/
18+
19+
/**
20+
* @param {number[]} nums
21+
* @param {number} k
22+
* @return {number}
23+
*/
24+
var minOperations = function(nums, k) {
25+
const queue = new MinPriorityQueue();
26+
let operations = 0;
27+
28+
nums.forEach(n => queue.enqueue(n));
29+
while (queue.size() >= 2 && queue.front().element < k) {
30+
queue.enqueue(queue.dequeue().element * 2 + queue.dequeue().element);
31+
operations++;
32+
}
33+
34+
return operations;
35+
};

0 commit comments

Comments
 (0)
Please sign in to comment.