[C++] : O(n) Time + O(1) space solution : Based on prefix minimum approach with explanation
INTIUTION\nVery staightforward idea -> to maximize the difference, we need to consider the minimum possible number till that point from start and max possible n
# **INTIUTION**\nVery staightforward idea -> to maximize the difference, we need to consider the minimum possible number till that point from start and max possible number from the end, right?\n\n# **IMPLEMENTATION**\nWe can maintain a global ans which we will keep maximizing as we move forward.\nWe will maintain a minimum variable which keep tracks on what minimum value has been encountered so far. \nAt every point while iteratng, we can check the difference of the value at that index with the minimum we have found till now and update the global answer we recieved so far.\n\n# **COMPLEXITY ANALYSIS**\n**Time Complexity** : O(n)    // only one traversal has been made\n**Space Complexity**: O(1)   //  no additional space allocated (only 2 variables)\n\n\n# **WORKING CODE**\n\n```\nint maximumDifference(vector<int>& nums) {\n        \n        int premin = INT_MAX, ans = 0;\n        \n        for(int i = 0; i < nums.size(); i++){\n            premin = min(premin, nums[i]);\n            ans = max(ans, nums[i] - premin);\n        }\n        \n        return ans == 0 ? -1 : ans;  // if ans == 0 means we got no valid answer (decreasing array)\n    }\n```\n\nPlease upvote if its of any help..\nCHEERS!!\nHappy Coding Guys...
['C', 'Prefix Sum']