Given an array of integers, write a method - maxGain - that returns the maximum gain. Maximum Gain is defined as the maximum difference between 2 elements in a list such that the larger element appears after the smaller element. If no gain is possible, return 0.
Since the larger element must always appear after the smaller element, this problem can be solved in a single pass. Keep a record of the maximum gain found so far, and the minimum element. When finding the maximum gain, use the difference between the current element and the minimum element found so far.