Java Solution - O(n)
\npublic int maximumDifference(int[] nums) {\n        int maxDiff = 0;\n        int minVal = Integer.MAX_VALUE;\n        \n        for(int i = 0; i < nums.lengt
```\npublic int maximumDifference(int[] nums) {\n        int maxDiff = 0;\n        int minVal = Integer.MAX_VALUE;\n        \n        for(int i = 0; i < nums.length; i++) {\n            minVal = Math.min(minVal, nums[i]);\n            maxDiff = Math.max(maxDiff, nums[i]-minVal);\n        }\n        \n        if(maxDiff == 0)\n            return -1;\n        \n        return maxDiff;\n    }\n```
[]