From ed40cc2fd12d61a2df544142d413d384eef6172f Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 8 Mar 2024 16:42:50 +0000 Subject: [PATCH] Add solutions --- python/minimum_operations_to_exceed_threshold_value_i.py | 7 +++++++ .../minimum_operations_to_exceed_threshold_value_ii.py | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 python/minimum_operations_to_exceed_threshold_value_i.py create mode 100644 python/minimum_operations_to_exceed_threshold_value_ii.py diff --git a/python/minimum_operations_to_exceed_threshold_value_i.py b/python/minimum_operations_to_exceed_threshold_value_i.py new file mode 100644 index 0000000..546234f --- /dev/null +++ b/python/minimum_operations_to_exceed_threshold_value_i.py @@ -0,0 +1,7 @@ +class Solution: + def minOperations(self, nums: List[int], k: int) -> int: + heapify(nums) + operations = 0 + while heappop(nums) < k: + operations += 1 + return operations \ No newline at end of file diff --git a/python/minimum_operations_to_exceed_threshold_value_ii.py b/python/minimum_operations_to_exceed_threshold_value_ii.py new file mode 100644 index 0000000..c207153 --- /dev/null +++ b/python/minimum_operations_to_exceed_threshold_value_ii.py @@ -0,0 +1,9 @@ +class Solution: + def minOperations(self, nums: List[int], k: int) -> int: + heapify(nums) + operations = 0 + while (x := heappop(nums)) < k: + y = heappop(nums) + heappush(nums, min(x,y)*2 + max(x,y)) + operations += 1 + return operations \ No newline at end of file