Java Solution in O(n) time complexity
\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        if(nums.length < 2)\n            return -1;\n        int result = Integer.MIN_VALUE;
```\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        if(nums.length < 2)\n            return -1;\n        int result = Integer.MIN_VALUE;\n        int minValue = nums[0];\n        for(int i = 1; i < nums.length; i++) {\n            if(nums[i] > minValue)\n                result = Math.max(result, nums[i] - minValue);\n            minValue = Math.min(minValue, nums[i]);\n        }\n        return result == Integer.MIN_VALUE ? -1 : result;       \n    }\n}\n```\nTime Complexity: O(n)\nSpace Complexity: O(1)\n\nGuy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE.
['Java']