3044. Minimum Operations to Collect Elements
My accepted Python solution to LeetCode problem 3044, Minimum Operations to Collect Elements, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.3MB
- 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 0ms, memory 17.3MB, accepted 2026-01-02.
class Solution:
def minOperations(self, nums: List[int], k: int) -> int:
collected = set()
for i in range(len(nums) - 1, -1, -1):
if nums[i] <= k:
collected.add(nums[i])
if len(collected) == k:
return len(nums) - i
return len(nums)