LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2026-01-02.

python
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)

Source