Concise Java, 6 lines, O(n) time, O(1) space
Do what the problem says. Keep track of index i such as a[i] = min of a[0...j]\n```java\n public int maximumDifference(int[] a) {\n        int r = -1, i = 0;\n 
Do what the problem says. Keep track of index ```i``` such as ```a[i] = min of a[0...j]```\n```java\n public int maximumDifference(int[] a) {\n        int r = -1, i = 0;\n        for (int j = 1; j < a.length; j++)\n            if (a[i] < a[j])\n                r = Math.max(r, a[j] - a[i]);\n            else i = j;\n        return r;\n    }
[]