@@ -0,0 +1,2328 @@
+import java.util.*;%0A%0Apublic class Solution %7B%0A%0A%09private int array%5B%5D;%0A    private int length;%0A %0A    public void sort(int%5B%5D inputArr) %7B%0A         %0A        if (inputArr == null %7C%7C inputArr.length == 0) %7B%0A            return;%0A        %7D%0A        this.array = inputArr;%0A        length = inputArr.length;%0A        quickSort(0, length - 1);%0A    %7D%0A %0A    private void quickSort(int lowerIndex, int higherIndex) %7B%0A         %0A        int i = lowerIndex;%0A        int j = higherIndex;%0A        // calculate pivot number, I am taking pivot as middle index number%0A        int pivot = array%5BlowerIndex+(higherIndex-lowerIndex)/2%5D;%0A        // Divide into two arrays%0A        while (i %3C= j) %7B%0A            /**%0A             * In each iteration, we will identify a number from left side which %0A             * is greater then the pivot value, and also we will identify a number %0A             * from right side which is less then the pivot value. Once the search %0A             * is done, then we exchange both numbers.%0A             */%0A            while (array%5Bi%5D %3E pivot) %7B%0A                i++;%0A            %7D%0A            while (array%5Bj%5D %3C pivot) %7B%0A                j--;%0A            %7D%0A            if (i %3C= j) %7B%0A                exchangeNumbers(i, j);%0A                //move index to next position on both sides%0A                i++;%0A                j--;%0A            %7D%0A        %7D%0A        // call quickSort() method recursively%0A        if (lowerIndex %3C j)%0A            quickSort(lowerIndex, j);%0A        if (i %3C higherIndex)%0A            quickSort(i, higherIndex);%0A    %7D%0A %0A    private void exchangeNumbers(int i, int j) %7B%0A        int temp = array%5Bi%5D;%0A        array%5Bi%5D = array%5Bj%5D;%0A        array%5Bj%5D = temp;%0A    %7D%0A%09%0A    public static void main(String args%5B%5D) %7B%0A%09%09Scanner in = new Scanner(System.in);%0A%09    int N = in.nextInt();%0A%09%09Solution sorter = new Solution();%0A%09    %0A%09    int%5B%5D horses = new int%5BN%5D;%0A%09    %0A%09    for(int i=0;i%3CN;i++)%7B%0A%09    %09horses%5Bi%5D = in.nextInt();%0A%09    %7D%0A%09    sorter.sort(horses);%0A%09    %0A%09    int closest = Integer.MAX_VALUE;%0A%09    for(int i=0;i%3CN;i++)%7B%0A%09    %09for(int j=i+1;j%3CN;j++)%7B%0A%09    %09%09if(Math.abs(horses%5Bi%5D - horses%5Bj%5D) %3C closest)%7B%0A%09    %09%09%09closest = Math.abs(horses%5Bi%5D - horses%5Bj%5D);%0A%09    %09%09%7D%0A%09    %09%09else if(horses%5Bi%5D - horses%5Bj%5D %3E 0 && horses%5Bi%5D - horses%5Bj%5D %3E closest)%7B%0A%09    %09%09%09break;%0A%09    %09%09%7D%0A%09    %09%7D%0A%09    %7D%0A%09    System.out.println(closest);%0A    %7D%0A%7D%0A

Create Solution.java