LeetCode solutions

2016. Reduction Operations to Make the Array Elements Equal

My accepted Python solution to LeetCode problem 2016, Reduction Operations to Make the Array Elements Equal, running in 108ms.

  • Difficulty: Medium
  • Python
  • Runtime 108ms
  • Memory 24.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 108ms, memory 24.4MB, accepted 2025-12-30.

python
class Solution:
    def reductionOperations(self, nums: List[int]) -> int:
        nums.sort()
        n = len(nums)
        result = 0
        count = 0
        
        for i in range(1, n):
            if nums[i] != nums[i - 1]:
                count += 1
            result += count
        
        return result

Source