Find integers that divides maximum number of elements of the array | Function to print the integers that divide the maximum number of elements from the array ; Initialize two lists to store rank and factors ; Start from 2 till the maximum element in arr ; Initialize a variable to count the number of elements it is a factor of ; Maximum rank in the rank list ; Print all the elements with rank m ; Driver code
def maximumFactor ( arr ) : NEW_LINE INDENT rank , factors = [ ] , [ ] NEW_LINE for i in range ( 2 , max ( arr ) + 1 ) : NEW_LINE INDENT count = 0 NEW_LINE for j in arr : NEW_LINE INDENT if j % i == 0 : count += 1 NEW_LINE DEDENT rank . append ( count ) NEW_LINE factors . append ( i ) NEW_LINE DEDENT m = max ( rank ) NEW_LINE for i in range ( len ( rank ) ) : NEW_LINE INDENT if rank [ i ] == m : NEW_LINE INDENT print ( factors [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 120 , 15 , 24 , 63 , 18 ] NEW_LINE maximumFactor ( arr ) NEW_LINE