Possible Duplicate:
Is it possible to find two numbers whose difference is minimum in O(n) time
For example, in [4, 2, 7, 11, 8], the algorithm should return abs(7-8) = 1.
The brute force way will be O(n2) and sorting will give O(nlogn). Is there more efficient way?
Thanks
I think sorting and comparing is going to be your best bet. Something like: