From e959868af361cbbe56eca4e540385c863b6af19f Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Thu, 13 Feb 2025 11:47:17 +0000 Subject: [PATCH] https://leetcode.com/problems/minimum-operations-to-exceed-threshold-value-ii --- ...operations_to_exceed_threshold_value_ii.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 medium/minimum_operations_to_exceed_threshold_value_ii.py 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 +