Find the size of distinct elements array if we pick any two elements and insert their absolute difference along with the two elements.
Input: size and elements
6
9 6 12 15 24 27
Output:
9
I tried to find gcd of elements and divide it with max element in the array ,but it is failing for some test cases. Please suggest the approach with optimum complexity
A naive approach would be to find the difference of every two element in the array add those differences which are not in the original array. But the complexity would be O(n^2)…