Difficult to answer in short and first time attempt.
Sigiloso
Its a forward difference, so you track the smallest number before your current number then you can get the biggest difference with the current number as the subtractor. If it means subtractor must be in earlier position than subtractee, reverse the algorithm. int min = array[0]; int max = Integer.MIN_VALUE; for (int i = 1; i < len; i++){ max = Math.max(max, array[i] - min); min = Math.min(min, array[i]); } return max;