Javascript O(n) Solution
Brute Force 0(n^2)\n\nvar maximumDifference = function(nums) {\n    var diff=-1\n    for(let i=0;i<nums.length;i++){\n        for(let j=i+1;j<nums.length;j++){\
# Brute Force 0(n^2)\n```\nvar maximumDifference = function(nums) {\n    var diff=-1\n    for(let i=0;i<nums.length;i++){\n        for(let j=i+1;j<nums.length;j++){\n            if (nums[j]> nums[i]) diff=Math.max(nums[j]-nums[i],diff)\n        }\n    }\n    return diff\n};\n```\n# DP 0(n)\n```\nvar maximumDifference = function(nums) {\n   var min=Infinity\n   var diff=-1\n   for(i=0;i<nums.length;i++){\n       min = Math.min(min,nums[i])\n       diff=Math.max(diff,nums[i]-min)\n   }\n   return diff==0 ? -1 : diff\n};\n```\n\n\n
['Dynamic Programming', 'JavaScript']