Minimum increments to modify array such that value of any array element can be splitted to make all remaining elements equal | Function to count minimum moves ; Stores sum of given array ; Stores maximum array element ; Base Case ; If N is 2 , the answer will always be 0 ; Traverse the array ; Calculate sum of the array ; Finding maximum element ; Calculate ceil ( sum / N - 1 ) ; If k is smaller than maxelement ; Final sum - original sum ; Print the minimum number of increments required ; Driver Code ; Given array ; Size of given array ; Function Call
def minimumMoves ( arr , N ) : NEW_LINE INDENT sum = 0 NEW_LINE maxelement = - 1 NEW_LINE if ( N == 2 ) : NEW_LINE INDENT print ( 0 , end = " " ) NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT sum += arr [ i ] NEW_LINE maxelement = max ( maxelement , arr [ i ] ) NEW_LINE DEDENT K = ( sum + N - 2 ) // ( N - 1 ) NEW_LINE K = max ( maxelement , K ) NEW_LINE ans = K * ( N - 1 ) - sum NEW_LINE print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 7 ] NEW_LINE N = 3 NEW_LINE minimumMoves ( arr , N ) NEW_LINE DEDENT