Make all array elements equal by repeated subtraction of absolute difference of pairs from their maximum | Function to return gcd of a and b ; Base Case ; Recursive call ; Function to find gcd of array ; Initialise the result ; Traverse the array arr [ ] ; Update result as gcd of the result and arr [ i ] ; Return the resultant GCD ; Given array arr [ ] ; Function call
def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def findGCD ( arr , N ) : NEW_LINE INDENT result = 0 NEW_LINE for element in arr : NEW_LINE INDENT result = gcd ( result , element ) NEW_LINE if ( result == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT arr = [ 2 , 3 , 4 ] NEW_LINE N = len ( arr ) NEW_LINE print ( findGCD ( arr , N ) ) NEW_LINE