CPP 0ms solution
\nclass Solution {\npublic:\n    int maximumDifference(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> rightmax(n,0);\n        rightmax[
```\nclass Solution {\npublic:\n    int maximumDifference(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> rightmax(n,0);\n        rightmax[n-1] = 0;int right = 0;\n        for(int i = n-2; i>=0 ; i--)\n        {\n          rightmax[i] = max(nums[i+1], right);\n            right = rightmax[i];\n        }\n        int ans = 0;\n        for(int i = 0 ;i< n ;i++)\n        {\n            if(nums[i] < rightmax[i])\n                ans = max(ans,abs(nums[i] - rightmax[i]));\n        }\n        if(ans == 0)\n            return -1;\n        return ans;\n    }\n};\n```
[]