Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 &lt;= i &lt; j &lt; n and nums[i] &lt; nums[j].

Return the maximum difference. If no such i and j exists, return -1.

&nbsp;
Example 1:

Input: nums = [7,1,5,4]
Output: 4
Explanation:
The maximum difference occurs with i = 1 and j = 2, nums[j] - nums[i] = 5 - 1 = 4.
Note that with i = 1 and j = 0, the difference nums[j] - nums[i] = 7 - 1 = 6, but i &gt; j, so it is not valid.


Example 2:

Input: nums = [9,4,3,2]
Output: -1
Explanation:
There is no i and j such that i &lt; j and nums[i] &lt; nums[j].


Example 3:

Input: nums = [1,5,2,10]
Output: 9
Explanation:
The maximum difference occurs with i = 0 and j = 3, nums[j] - nums[i] = 10 - 1 = 9.


&nbsp;
Constraints:


	n == nums.length
	2 &lt;= n &lt;= 1000
	1 &lt;= nums[i] &lt;= 109


class Solution:
    def maximumDifference(self, nums: List[int]) -> int:
        curmin = nums[0]
        diff = 0
        for num in nums:
            diff = max(diff, num - curmin)
            curmin = min(curmin, num)
        return diff or -1
class Solution {
    public int maximumDifference(int[] nums) {
        if(nums.length < 2)
            return -1;
        int result = Integer.MIN_VALUE;
        int minValue = nums[0];
        for(int i = 1; i < nums.length; i++) {
            if(nums[i] > minValue)
                result = Math.max(result, nums[i] - minValue);
            minValue = Math.min(minValue, nums[i]);
        }
        return result == Integer.MIN_VALUE ? -1 : result;
    }
}
class Solution {
public:
    int maximumDifference(vector<int>& nums) {
        int mn = nums[0], res = 0;
        for (int i = 1; i < nums.size(); i++) {
            res = max(res, nums[i] - mn);
            mn = min(mn, nums[i]);
        }
        return res == 0 ? -1 : res;
    }
};
var maximumDifference = function(nums) {
    var diff=-1
    for(let i=0;i<nums.length;i++){
        for(let j=i+1;j<nums.length;j++){
            if (nums[j]> nums[i]) diff=Math.max(nums[j]-nums[i],diff)
        }
    }
    return diff
};
Maximum Difference Between Increasing Elements