Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.06 KB

_3396. Minimum Number of Operations to Make Elements in Array Distinct.md

File metadata and controls

43 lines (31 loc) · 1.06 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : April 08, 2025

Last updated : April 08, 2025


Related Topics : Array, Hash Table

Acceptance Rate : 71.54 %


Solutions

Python

class Solution:
    def minimumOperations(self, nums: List[int]) -> int:
        cnt = Counter(nums)
        above = sum([1 for v in cnt.values() if v > 1])

        for i, c in enumerate(nums) :
            if above == 0 :
                return ceil(i / 3)
            if cnt[c] == 1 :
                cnt.pop(c)
            cnt[c] -= 1
            if cnt[c] == 1 :
                above -= 1

        return ceil(len(nums) / 3)