@@ -0,0 +1,1370 @@
+package coding4fun;%0A%0Aimport java.util.TreeSet;%0A%0A/**%0A * Find the maximum difference of two elements in an array, such that%0A * array%5Bi%5D - array%5Bj%5D is maximum where i %3C j.%0A *%0A * %3Cpre%3E%0A * Input : %5B4, 1, 2, 3%5D%0A * Output: 2%0A *%0A * Input:  %5B2, 3, 10, 2, 4, 8, 1%5D%0A * Output: 8%0A *%0A * Input:  %5B1, 3, 10, 2, 4, 8, 100%5D%0A * Output: 99%0A *%0A * Input:  %5B7, 9, 5, 6, 3, 2%5D%0A * Output: 2%0A *%0A * Input:  %5B1, 2, 3, 4, 5%5D%0A * Output: 4%0A *%0A * Input:  %5B5, 4, 3, 2, 1%5D%0A * Output: -1%0A * %3C/pre%3E%0A */%0Apublic class Problem45 %7B%0A    private static int maxDiff(int%5B%5D array) %7B%0A        TreeSet%3CInteger%3E set = new TreeSet%3C%3E();%0A        int min = Integer.MIN_VALUE;%0A        for (int i = 0; i %3C array.length; i++) %7B%0A            if (set.size() %3E 0) %7B%0A                int smallest = set.first();%0A                min = Math.max(min, array%5Bi%5D - smallest);%0A            %7D%0A            set.add(array%5Bi%5D);%0A        %7D%0A        return min;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(maxDiff(new int%5B%5D%7B4, 1, 2, 3%7D)); // 2%0A        System.out.println(maxDiff(new int%5B%5D%7B2, 3, 10, 2, 4, 8, 1%7D)); // 8%0A        System.out.println(maxDiff(new int%5B%5D%7B1, 3, 10, 2, 4, 8, 100%7D)); // 99%0A        System.out.println(maxDiff(new int%5B%5D%7B7, 9, 5, 6, 3, 2%7D)); // 2%0A        System.out.println(maxDiff(new int%5B%5D%7B1, 2, 3, 4, 5%7D)); // 4%0A        System.out.println(maxDiff(new int%5B%5D%7B5, 4, 3, 2, 1%7D)); // -1%0A    %7D%0A%7D%0A

Add problem 45