C++ solution
\n\n# Approach \nKeep track of the minimum while traversing the array and update the answer if found a greater element than the minimum\n Describe your approach
\n\n# Approach \nKeep track of the minimum while traversing the array and update the answer if found a greater element than the minimum\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maximumDifference(vector<int>& nums) {\n        int ans=INT_MIN;\n        int mi =INT_MAX;\n        for(auto x:nums)\n        {\n            mi=min(mi,x);\n            ans=max(ans,x-mi);\n        }\n\n        return ans==0 ? -1 : ans;\n    }\n};\n```
['C++']