/**
public class MaxGap {
public static int maxGap(int[] arr) {
if (arr == null || arr.length < 2) {
return 0;
}
int len = arr.length;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (int i : arr) {
max = Math.max(i, max);
min = Math.min(i, min);
}
if (max == min) {
return 0;
}
int[] maxArray = new int[len + 1];
int[] minArray = new int[len + 1];
boolean[] hasNum = new boolean[len + 1];
int t = 0;
for (int j : arr) {
t = bucket(j, len, min, max);
maxArray[t] = hasNum[t] ? Math.max(maxArray[t], j) : j;
minArray[t] = hasNum[t] ? Math.min(minArray[t], j) : j;
hasNum[t] = true;
}
int res = 0;
int lastMax = maxArray[0];
for (int i = 1; i <= len; i++) {
if (hasNum[i]) {
res = Math.max(res, minArray[i] - lastMax);
lastMax = maxArray[i];
}
}
return res;
}
public static int bucket(long num, long len, long min, long max) {
return (int) ((num - min) * len / (max - min));
}
// for test
public static int comparator(int[] nums) {
if (nums == null || nums.length < 2) {
return 0;
}
Arrays.sort(nums);
int gap = Integer.MIN_VALUE;
for (int i = 1; i < nums.length; i++) {
gap = Math.max(nums[i] - nums[i - 1], gap);
}
return gap;
}
// for test
public static int[] generateRandomArray(int maxSize, int maxValue) {
int[] arr = new int[(int) ((maxSize + 1) * Math.random())];
for (int i = 0; i < arr.length; i++) {
arr[i] = (int) ((maxValue + 1) * Math.random()) - (int) (maxValue * Math.random());
}
return arr;
}
// for test
public static int[] copyArray(int[] arr) {
if (arr == null) {
return null;
}
int[] res = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
res[i] = arr[i];
}
return res;
}
// for test
public static void main(String[] args) {
int testTime = 500000;
int maxSize = 100;
int maxValue = 100;
boolean succeed = true;
for (int i = 0; i < testTime; i++) {
int[] arr1 = generateRandomArray(maxSize, maxValue);
int[] arr2 = copyArray(arr1);
if (maxGap(arr1) != comparator(arr2)) {
succeed = false;
break;
}
}
System.out.println(succeed ? "Nice!" : "Fucking fucked!");
}
}