Unless I misunderstand the question I believe you can do this in one pass of the array. You just need to keep track of the maximum value and maximum difference you have seen so far. As you go through the array calc the difference between the current number and the maximum seen so far.
So for your second example 5, 21, 3, 22, 12, 7, 26, 14
1: 5 is first value so set maximum to 5
2: 21 > 5 so reset maximum
3: 21 - 3 = 18
4: 22 > 21 so reset maximum
5: 22 - 12 = 10
6: 22 - 7 = 15
7: 26 > 22 so reset maximum
8: 26 - 14 = 12
As the smaller number comes after the larger when you find a new maximum any smaller number beyond it in the array needs to be subtracted from this new maximum.
The answer required is the maximum value seen during this process - in this case the 18 that is calulated in step 3.