Find the largest possible difference in an array of integers, such that the smaller integer occurs earlier in the array.
Anonymous
Iterate over the list, updating two variables each time: the minimum element seen so far and the maximum difference possible so far (calculated as the max of the current max difference and the difference of the current element and the current known minimum). This works in O(n) time with O(1) storage.
Check out your Company Bowl for anonymous work chats.