Anser will be O(nlogn), for any number it will give minimum differnece either with the number which is just higher to it or just lower to it and and have no benefit to check any number with all other number ( waste of iteration ).
And if you sort the array , then it will fulfill our requirements, for any ith number the number which is just greater then equals to it will be present on (i + 1 )th position and one which is just lower and equals to it is at position ( i - 1 ).
Pseudo code :
sort(arr , arr + n ) // 0 indexing based array
int res = infinite ;
for(int i = 1 ; i < n ; ++i ) res = min( res , arr[i] - arr[i - 1] )
return res;
Complexity : (nlogn + n ) = o(nlogn)
As sorting also can be done in linear time with hashing( counting sort ) but they are asking for worst case , then we can assume sorting complexity to nlogn.
Hence option 2 is correct : O(nlogn)