Java O(n) solution
\npublic int maximumDifference(int[] nums) {\n    int result = -1;\n    int pointer1 = 0;\n    int pointer2 = 1;\n\n    while (pointer2 < nums.length) {\n      
```\npublic int maximumDifference(int[] nums) {\n    int result = -1;\n    int pointer1 = 0;\n    int pointer2 = 1;\n\n    while (pointer2 < nums.length) {\n        int diff = nums[pointer2] - nums[pointer1];\n\n        if (diff < 0) {\n            pointer1 = pointer2;\n        } else if (diff > 0 && diff > result) {\n            result = diff;\n        }\n\n        pointer2++;\n    }\n\n    return result;\n}\n```
['Java']