I liked this puzzle a lot and wanted to share my solution and how i did it. I coded in C#
As all of you guys did, i put all the values in a list ( array would also work ). I found the solution with only one for loop. Outside of the for loop, i defined 4 variables, 3 being integer and 1 being a boolean. Those variables are: int heighestValue, lowestValue, deltaValue and bool valuesChanged.
I initiated this variables with;
heighestValue = 0
lowestValue = int.MaxValue
deltaValue = 0
valuesChanged = false
In the for loop, i first compared the value in the list with the heighestValue, if the value in the list is higher than the highestValue (which in the first time it would always be higher because highestValue initiated with the value of 0 ) i set the heighestValue to value on the list. I also set the boolean valuesChanged to true.
If the value on the list is not higher than the heighestValue, i compared it with the lowestValue. If the value on the list is lower than lowestValue, i set lowestValue to the value on the list and i set the boolean valuesChanged to true.
After comparing those integers, i checked if valuesChanged variable is true. If it is true i calculated the currentDelta
int currentDelta = lowestValue - heighestValue
Because of the solution wants the answer in negatve, i decided to just substract the heigher value from the lower value.
After finding currentDelta, i compared it with the deltaValue variable that i defined before the for loop. If currentDelta is smaller than the deltaValue, i set the deltaValue to currentDelta. After this if statement i reseted the value of lowestValue to int.MaxValue, the reason behind that is i dont want any other higher values after this value to interact with this lowestValue. If you do not set the lowestValue to int.MaxValue ( it doesn't have to be int.MaxValue, but it is good to be safe), as can be seen in the first example, it would subtract the last value of 5 from the previous value 1 and resulting a currentDelta of -4. That is why you need to reset the lowest value for each valuesChanged.
I will write my code down just in case of if i couldn't explained it well. I am a non-english speaking person, so i really suffer writing anything in English. Good luck
[[EDIT: NO FULL CODE]]