Leetcode 1674 Solution

This article provides solution to leetcode question 1674 (minimum-operations-to-make-array-equal)

https://leetcode.com/problems/minimum-operations-to-make-array-equal

Solution

class Solution:
    def f(self, i):
        if i == 0:
            return 0
        elif i == 1:
            return 0

        return self.f(i - 2) + i - 1

    def minOperations(self, n: int) -> int:
        if n <= 1:
            return 0

        if n % 2 == 1:
            return int((n - 1)/2 * ((n - 1)/2 + 1))
        else:
            return int(n * n / 4)