• + 1 comment

    This question is misleading! When I test my code below to equate all numbers in the list and count number of operations, I get the minimum number of operations compared to the ones gotten on their test cases, so my code does not pass their test cases!

    def equal(arr):
        # Write your code here
        count = 0
        
        while max(arr)!= min(arr):
            mx = max(arr)
            mn = min(arr)
            diff = mx-mn
            
            addValue = 5
            if 2<=diff<5:
                addValue = 2
            if diff==1:
                addValue = 1
            
            numberOfMx = arr.count(mx)
            arr = [a+addValue for a in arr if a!=mx]+[mx for num in range(numberOfMx)]
            count += 1
        print("Final arr:",arr)
        print("Length of arr:",len(arr))
                
        return count