diff --git a/medium/minimum_operations_to_exceed_threshold_value_ii.py b/medium/minimum_operations_to_exceed_threshold_value_ii.py new file mode 100644 index 0000000..483712a --- /dev/null +++ b/medium/minimum_operations_to_exceed_threshold_value_ii.py @@ -0,0 +1,20 @@ +# https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii + +from typing import List +import heapq + +class Solution: + def minOperations(self, nums: List[int], k: int) -> int: + q: List[int] = [] + for num in nums: + heapq.heappush(q, num) + result = 0 + while len(q) > 0: + x = heapq.heappop(q) + if x >= k: + break + y = heapq.heappop(q) + heapq.heappush(q, min(x, y) * 2 + max(x, y)) + result += 1 + return result +