Maximum Difference

How to solve the following problem?

Maximum Difference

Given an unsorted array of N unique integers, find the maximum difference (absolute) between any two numbers such that their difference divides all the other numbers of the array. Print that particular pair of numbers in ascending order. If there are more than one such pairs, print the pair which has the maximum sum. Print 0, if no such pair exist.

Input format
Read the input from standard input stream. First line gives the number of integers N. Second line gives array elements separated by comma

Output format
Print the pair of numbers separated by comma, 0 otherwise. Write the output to standard output stream

Sample Input
7
2,4,6,8,12,14,16

Sample Output
14,16

Explanation
14,16 is the pair which gives the maximum difference which divides all other elements of the array and has maximum sum.

Comments (4)