// [2, 4, 7, 1, 7, 2]
// [4, 2] => 0
// [1, 3, 4]
// [3, 1, 7]
public static int maxDiff(int[] arr){
int maxDiff = 0;
if(arr != null && arr.length > 1){
int len = arr.length;
int min = arr[0];
for(int i=1; i<len; i++){
if(arr[i-1] < min)
min = arr[i-1];
if(arr[i] - min > maxDiff)
maxDiff = arr[i] - min;
}
}
return maxDiff;
}