• + 39 comments

    If you sort the array, you only have to compare the first and last elements, thereby acheiving n*log(n) performance (Java Arrays.sort) instead of quadratic (comparing every pair).