Find the size of array

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)…

I tried this. But this approach will fail when the input is
7
3 6 12 15 24 27 29

Output
29

You can use set <int> DISTINCT here as set only contains distinct elements. size of the set DISTINCT.size() will be the answer.

Well can't tell you about optimization now :shushing_face:

Can you share the problem Link.