Minimum increments by index value required to obtain at least two equal Array elements | Function to update every element adding to it its index value ; Function to check if at least two elements are equal or not ; Count the frequency of arr [ i ] ; Function to calculate the number of increment operations required ; Stores the minimum number of steps ; Driver code
def update ( arr , N ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT arr [ i ] += ( i + 1 ) ; NEW_LINE DEDENT DEDENT def check ( arr , N ) : NEW_LINE INDENT f = 0 ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT count = 0 ; NEW_LINE for j in range ( N ) : NEW_LINE INDENT if ( arr [ i ] == arr [ j ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT if ( count >= 2 ) : NEW_LINE INDENT f = 1 ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( f == 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT def incrementCount ( arr , N ) : NEW_LINE INDENT min = 0 ; NEW_LINE while ( check ( arr , N ) != True ) : NEW_LINE INDENT update ( arr , N ) ; NEW_LINE min += 1 ; NEW_LINE DEDENT print ( min ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 ; NEW_LINE arr = [ 12 , 8 , 4 ] ; NEW_LINE incrementCount ( arr , N ) ; NEW_LINE DEDENT