3621. Minimum Operations to Make Array Values Equal to K
My accepted Python solution to LeetCode problem 3621, Minimum Operations to Make Array Values Equal to K, running in 67ms.
- Difficulty: Easy
- Python
- Runtime 67ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 67ms, memory 17.2MB, accepted 2025-12-31.
class Solution:
def minOperations(self, nums: List[int], k: int) -> int:
# If any element is less than k, it's impossible
if min(nums) < k:
return -1
# Count distinct values greater than k
distinct_values = set()
for num in nums:
if num > k:
distinct_values.add(num)
# We need one operation per distinct value > k
return len(distinct_values)