[Java/Python 3] Time O(n) space O(1) codes w/ brief explanation and a similar problem.
Similar Problem: 121. Best Time to Buy and Sell Stock\n\n----\n\nTraverse input, compare current number to the minimum of the previous ones. then update the max
**Similar Problem:** [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock)\n\n----\n\nTraverse input, compare current number to the minimum of the previous ones. then update the max difference.\n```java\n    public int maximumDifference(int[] nums) {\n        int diff = -1;\n        for (int i = 1, min = nums[0]; i < nums.length; ++i) {\n            if (nums[i] > min) {\n                diff = Math.max(diff, nums[i] - min);\n            }\n            min = Math.min(min, nums[i]);\n        }\n        return diff;\n    }\n```\n```python\n    def maximumDifference(self, nums: List[int]) -> int:\n        diff, mi = -1, math.inf\n        for i, n in enumerate(nums):\n            if i > 0 and n > mi:\n                diff = max(diff, n - mi)    \n            mi = min(mi, n)\n        return diff    \n```
['Java', 'Python3']