@@ -0,0 +1,1307 @@
+package problems;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class MaximumGap %7B%0A%0A    class Bucket %7B%0A        int min, max, count;%0A%0A        Bucket() %7B%0A            count = 0;%0A        %7D%0A%0A        public void add(int t) %7B%0A            if (count == 0)%0A                min = max = t;%0A            else %7B%0A                min = Math.min(min, t);%0A                max = Math.max(max, t);%0A            %7D%0A            count++;%0A        %7D%0A    %7D%0A%0A    public int maximumGap(int%5B%5D num) %7B%0A        if (num == null %7C%7C num.length == 0)%0A            return 0;%0A%0A        int N = num.length, min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;%0A        for (int t : num) %7B%0A            min = Math.min(min, t);%0A            max = Math.max(max, t);%0A        %7D%0A%0A        List%3CBucket%3E Bu = new ArrayList%3CBucket%3E(N - 1);%0A        for (int i = 0; i %3C N - 1; i++)%0A            Bu.add(new Bucket());%0A        for (int t : num) %7B%0A            if (t != min && t != max)%0A                Bu.get().add(t);%0A        %7D%0A        int gap = Math.max(Bu.get(0).min - min, max - Bu.get(N - 2).max);%0A        for (int i = 0; i %3C N - 1; i++)%0A            gap = Math.max()%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        MaximumGap mg = new MaximumGap();%0A        int%5B%5D num = %7B 2, 99999999 %7D;%0A        System.out.println(mg.maximumGap(num));%0A    %7D%0A%7D%0A

Add Maximum Gap